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 Accessibility 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 "Accessibility" Watch "Accessibility" New topic


Kalpesh Pandya

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 !!!
Kalpesh Pandya

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

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:
subject: Accessibility
It's not a secret anymore!