• Post Reply Bookmark Topic Watch Topic
  • New Topic

Private fields declared in super class exist in subclass instance?  RSS feed

 
Arav Kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all Ranchers,

In a java program where we have inheritance relationship between parent class and its child class, the private fields defined in the parent class explicitly initialized from the child class constructor with call of super (arguments). My question is do the private fields defined in the parent class exist in the child class instance memory space with the initialized values.

Please explain.

Regards
Arav Kumar
 
M K Rayapudi
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is do the private fields defined in the parent class exist in the child class instance memory space with the initialized values.


yes, exists.
 
Arav Kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. But please can you explain because private members don't get inherited in the subclass but yes they are present in the sub class instance.

 
M K Rayapudi
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at this link

read Private Members in a Superclass heading
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are inherited, they just aren't visible to the sub class.

I don't care what that article says, I can get the private fields using reflection so to me that means they are inherited.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each object has a component from its class and a component inherited from its superclass. The private superclass fields are in the latter part.
 
M K Rayapudi
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob Prime,
They are inherited, they just aren't visible to the sub class.

I don't care what that article says, I can get the private fields using reflection so to me that means they are inherited.


I have posted before your post

I agree with your views on the Inheritance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!