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

Access method

Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 168
My problem is that B has extend A and the doStuff() method in A is protected access, then why B cannot acccess doStuff() ?

Thanks in advance!
[ June 04, 2003: Message edited by: Jack Lau ]
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
it seems that there is a mistake
should be
package A;

SCJP 2 1.4
Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 168
Oh, I know that why class B cannot access the doStuff() method of class A because protected member can be only seen by subclass through inheritance, but cannot using dot to reference it.
Brian Joseph
Ranch Hand

Joined: May 16, 2003
Posts: 160
Hi Jack,
You're right. But also this question is testing whether you know that protected is very similiar to default (package) access.
If A and B were in the same package, you COULD call A's method like that.
We were just talking about this yesterday and Anupam posted a great link explaining this:
Link To Protected Access Discussion (See Kathy's reply)
[ June 04, 2003: Message edited by: Brian Joseph ]
I agree. Here's the link:
subject: Access method
jQuery in Action, 3rd edition