• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why don't protected inner class compile?

 
zhang feng
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
zhang feng
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh,it's running good ,thank you
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic