wood burning stoves 2.0*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q on overriding" Watch "Q on overriding" New topic
Author

Q on overriding

srini v
Greenhorn

Joined: Dec 15, 2003
Posts: 11
Hi:


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

to

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

Joined: Nov 04, 2003
Posts: 46
Hi,
'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
Greenhorn

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

Joined: Dec 15, 2003
Posts: 11
Hari, Lee thanks for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Q on overriding
 
Similar Threads
Static declaration
Method invoking
Hiding of instance variables. Hard question?
Section 6.6.7 of JLS ?
Protected Access Modifier...