aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Accessibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Accessibility" Watch "Accessibility" New topic
Author

Accessibility

Kalpesh Pandya
Greenhorn

Joined: Oct 07, 2000
Posts: 14
This Question was originally posted by Manish.
I don't know how to re-open already posted topic, so I am posting it again.
public class Tester {
public static void main(String[] args) {
System.out.println(new Sub().g());
}
private int f() {
return 2;
}
int g() {
return f();
}
}
class Sub extends Tester {
public int f() {
return 1;
}
}
I think output should be 1 but it is printing 2.
Methods can be overridden to be more public...then also ???
Please correct me !!!
Manish
Kalpesh Pandya
Greenhorn

Joined: Oct 07, 2000
Posts: 14
Hi manish,
If you remove private from the method f() than it will print 1 as output. Private methods cannot be overridden, as they are not visible to sub class. method f() in subclass has nothing to do with method f() in super class. So when g() of super class is calling f(), only method available in super class is f() with return 2.
Hope this will help you !
Correct me if I am wrong, because earlier explanation given by others to this question confused me a lot !
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Hi Kalpesh!
If you want to answer smbd question, you can hit blue button "Post Reply" at the top or at the bottom of the page.


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessibility
 
Similar Threads
Accessibility
Overriding Private Methods
overriding a method
Override or not?
2 questions on private methods !!