4
Answers

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

Akhil Khare

Akhil Khare

10y
1.1k
1
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)