Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes protected access 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 "protected access" Watch "protected access" New topic

protected access

Rishi Wright
Ranch Hand

Joined: Jun 25, 2003
Posts: 46
Hi 'all
say A & B are classes in different PACKAGES
and B extends A
1)how can I call a PROTECTED OVERRIDEN method in A from B
2)How can I access the STATIC PROTECTED method of A from B
a simple example would be more helpfullllll.....
thank you
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi Rishi,
Here is the example,

output is,
A.protected static:A
You get it?
Rishi Wright
Ranch Hand

Joined: Jun 25, 2003
Posts: 46
Thnx Maulin...I wanted to confirm there is no other way to call superclass overridden method other than using super (I mean any reference variable)..
thnx agian
Selim Hendrickson

Joined: Aug 14, 2003
Posts: 9
Maulin I'm confused. I thought the extending class would not be able to invoke protected methods through reference. Is super an exception to this rule?
I agree. Here's the link:
subject: protected access
It's not a secret anymore!