Akhil Khare

Akhil Khare

  • NA
  • 267
  • 53.8k

How we can assign the value to private data member of class

Jul 24 2014 5:54 AM
As we all know that private data members are not accessible from outside of class, but suppose if we need to assign any value to private data member then how we can do that without creating object of class or using any kind of reflection
Class ABC
{
      private int x; 
      ABC(int temp_x){this.x = temp_x;}
}
Class XYZ : ABC 
{
      //class XYZ declaration
 
by constructor we can assign the value when we creating the object of class. But is there any way to assign value to variable x without creating any object of ABC.  
 

Answers (4)