GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes why don't protected inner class  compile? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why don Watch "why don New topic
Author

why don't protected inner class compile?

zhang feng
Greenhorn

Joined: Dec 16, 2002
Posts: 19
i have a three .java files followed:

when i compiling the LittleDog,show the WhiteDog() has protected access in the myclass2.Dog.WhiteDog
How can I access the WhiteDog in the LittleDog.java
[ June 11, 2003: Message edited by: zhang feng ]
[ June 11, 2003: Message edited by: zhang feng ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi zhang,
Welcome to JavaRanch. First off you had several other problems in your code. For your question, since you did not provide a public default constructor for WhiteDog, the compiler created a protected default constructor which is the access level of the enclosing class. LittleDog has no relationship to WhiteDog, so it can only access WhiteDog's public memebers. All you have to do to fix the problem is provide a default public constructor. I fixed some of your code here:
Animal.java


Dog.java

LittleDog.java


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
zhang feng
Greenhorn

Joined: Dec 16, 2002
Posts: 19
oh,it's running good ,thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why don't protected inner class compile?