wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 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 methods" Watch ""Overriding" private methods" New topic
Author

"Overriding" private methods

Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
While taking a mock exam, I ran into the following question:
Q: Which of the following are true:
One of the options was:
"A private method can not be overriden and made public."
The answer that was given in the exam was that this is a false statement. However, even though it's true that, when overriding methods, you can make them "more public," you can't override a private method, right? If you can't override a private method, you can't override it to make it public, right?
Just a quick addition to this question. If class B extends class A, which contains a private member C, is B considered to inherit B from A even though it doesn't have access to it?
Thanks,
Corey


SCJP Tipline, etc.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
private methods are not inherited, and thus, cannot be overridden. That does not mean that you can't have a method in the subclass having the same signature than the method in the superclass, but this is not overriding...
See this code:

You can have a method in the subclass having the same signature than a private method in the superclass, but overriding does not apply because the private method is not inherited...


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Thanks, Val - that's just what I thought.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "Overriding" private methods