aspose file tools*
The moose likes Beginning Java and the fly likes method overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method overriding" Watch "method overriding" New topic
Author

method overriding

Komal Amaresh
Ranch Hand

Joined: Oct 06, 2008
Posts: 67
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

Joined: Oct 13, 2005
Posts: 39415
    
  28
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Sagar Rohankar wrote:coz

Please Use Real Words.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: method overriding