jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Simple Q, I'm newbie 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 "Simple Q, I Watch "Simple Q, I New topic

Simple Q, I'm newbie

Alberto Dal Dosso

Joined: Jun 15, 2005
Posts: 2

I think this code will not compile:

class Zoo{
protected String coolMethod(){
return "Wow baby";

class Moo extends Zoo {
public void useMyCoolMethod() {
System.out.println("Moo says, " + this.coolMethod());

Zoo z = new Zoo();
System.out.println("Zoo says, " + z.coolMethod());

class Boo {
public void useMyCoolMethod() {
Zoo z = new Zoo();
System.out.println("Zoo says, " + z.coolMethod());

But it compile, why? I think than I can't call a protected method from Boo class.
shetal bansal
Ranch Hand

Joined: May 09, 2005
Posts: 63
Protected members are visible to all the classes in the same package.
As Boo and Zoo are in the same package, protected method coolMethod() in Zoo is available to Boo.
Place Boo in a different package and try compiling, u`ll get a compile time error.
I agree. Here's the link: http://aspose.com/file-tools
subject: Simple Q, I'm newbie
It's not a secret anymore!