This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q on overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q on overriding" Watch "Q on overriding" New topic

Q on overriding

srini v

Joined: Dec 15, 2003
Posts: 11

When cut and past the above code, it prints "C.m" as expected.
When I change the code


I get "B.m".
Please clarify?
H Gokulam
Ranch Hand

Joined: Nov 04, 2003
Posts: 46
'default access' means accessable only in the same package.
'protected access' means accessable to all classes derived from this class evenif the class is in a different package.
You changed protected access to default access. ie: by doing that you made that method (void m()) not accessable outside the package.
So the method protected void m(){ System.out.println("C.m"); in class C is not overriding the method in class B, it is just hiding/shadowing the method in class B.
Hope it is clear now.

Harikumar G<br />SCJP 1.4
Lee Ming

Joined: Dec 15, 2003
Posts: 16
hi srinivasan,
You can find more information about method access controllhere
srini v

Joined: Dec 15, 2003
Posts: 11
Hari, Lee thanks for your help.
I agree. Here's the link:
subject: Q on overriding
It's not a secret anymore!