• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inherited Method  RSS feed

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

May I know if Class B inherits from Class A, will the private methods in Class A be extended to Class B too?

Thank you.
 
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jessica,

I think by:
methods in Class A be extended to Class B


You intend to say that are they accessible from Class B.

No, private methods are accessible only from within that class.

If you want these methods of Class A to be accessible from its subclass i.e. Class B in this case then you could make them protected. This will allow a subclass residing outside the package of its superclass to access these methods.

If the subclass is in the same package as the super class then default access for the method will do. That is specifing no access modifier before the method signature.

If you want more info then search for java access modifiers for methods on the net:
It will give you details about the modifiers: public , protected , default and private.

This should clarify all your doubts.

 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If these methods were private, it was in order that they be not accessible. There was surely a good reason for making the private; don't change the access modifier.
 
Jessica Ngui
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priety Sharma and Campbell Ritchie,

Thanks for the clarifications :=)
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!