File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Method Overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Method Overriding" Watch "Method Overriding" New topic

Method Overriding

Mukesh Rathod
Ranch Hand

Joined: Oct 11, 2000
Posts: 32
The rule of method overridding says that "The overridding Method can not be less accessible than the overridden method"
Hence a private method can be overidden by "friendly, protected ot public methods.
However, the private methods can not be overridden.
Also abstract methods can not be private.
Can someone explain this concept?
Raghvendra Sharma
Ranch Hand

Joined: Oct 09, 2000
Posts: 82
Sorry, but U are interpreting the sentence in a wrong way.
The statement says, no method can be overridden to be less accessible i.e. you can't make a method protected if it was public originally, or you can't make a method private from protected etc.
so please make your interpretation correct.
hope to help you.
[This message has been edited by Raghvendra Sharma (edited October 12, 2000).]
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi Mukesh,
let me try to explain it with example.

now let's make the method private

So u see Mukesh that u can't access the private methods in derived class.and since u can't access them so when u define a method with the same name in the derived class u r definitely not ovrriding the base class function.
instead such a situation u r said to be hiding the base class function.
for your next doubt
abstract methods can not be private.
as must be clear from the above text that
private methods - are not available in derived class
abstract methods - have have to be available in the derived class because they are meant to be implemented by the derived class somewhere down the line.
so don't you think that the feature/requirements of private and abstract modifires are so contrdictory that nobody would need/wish to use them together. so it's defined illegal by java lang.
what do u think now?

Mukesh Rathod
Ranch Hand

Joined: Oct 11, 2000
Posts: 32
Thanks deekasha
I agree. Here's the link:
subject: Method Overriding
It's not a secret anymore!