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 Overriding Private method 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 "Overriding Private method" Watch "Overriding Private method" New topic

Overriding Private method

umar hathab
Ranch Hand

Joined: Aug 20, 2001
Posts: 52
Can we override private method?(I am able to override but i have some confusions)

Sun Certified Java Programmer for Java 2.0 (93%) <p>----Winners always make the learning a habit
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Dear Umar,
You can override private method with private, default(friendly), protected, or public method in subclass.
If you have default(friendly) method, it can override with friendly, protected or public method.
If you have protected method, it can override with protected or public method.
If you have public method, it can override only with public method.
Hope this help you
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3634
You can only override something that you already have. private methods are not inherited by the subclass and so there is no question of overriding it.
You can obviously have a method in subclass with the same signature as the method in baseclass but it would have no relation to the base class method. It would be as independent as any other method with different signature.

SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
No private methods can not be overrriden because they are not inhereted and because they are statically binded -as static ones-
If you place a method with the same signature as a private one declared in a superclass you won't obtain the polymorphic beheavior that is common for instance methods:

Here you will see method in Fahter is called. Compare it with the result if placing public instead

SCJP2. Please Indent your code using UBB Code
I agree. Here's the link:
subject: Overriding Private method
It's not a secret anymore!