Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method overriding

 
Komal Amaresh
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir,

It is mentioned that a subclass method can have the same signature and the name of a private method decalared in the super class. The primary purpose of declaring a private method is lost is so as the basic aim of creating a private method is to implement encapsulation. Besides as the main is declared in the child class, what is the use of creating a private method in the super class. Please explain.

Thanks in advance.

with regards,
Komal Amaresh
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same as in the superclass. It provides a method for use only inside that class. If you use the superclass properly, by reading its javadoc comments rather than its code, you should never even know you are "overriding" a private method.

I am not sure, but I don't think it's really overriding or hiding, because the subclass is not "aware" of a private superclass method. It is more like writing a new method. Anybody wish to correct me on that point?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:

I am not sure, but I don't think it's really overriding or hiding, because the subclass is not "aware" of a private superclass method. It is more like writing a new method. Anybody wish to correct me on that point?


I agreed . private method can't overridden, coz sub class never inherit them and about hiding, they are not static.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:coz

Please Use Real Words.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic