This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Protected access from subclass in different package
jason adam
Chicken Farmer ()
Ranch Hand
Joined: May 08, 2001
Posts: 1932
posted
0
I understand that if a subclass is in a different package than its super it can't directly access any protected members, but instead gets its own inherited copy to deal with. The same should go for inner classes. However, the following code fails, and I can't seem to determine why. The commented out section of course would give a compiler error, it's p2 that I don't understand why it is giving an error also.
Any ideas? Jason
jason adam
Chicken Farmer ()
Ranch Hand
Joined: May 08, 2001
Posts: 1932
posted
0
Ok, I added a public no-argument constructor that does nothing to my inner class, and it compiles fine. Why? What is it about inner classes and constructors that made this fail? Does the default constructor get created with protected access also and therefore only accessible by subclasses of the inner class, or classes in the same package? Jason
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
A default constructor has the same access level as the class it's associated with. The JLS describes this here.
"I'm not back." - Bill Harding, Twister
jason adam
Chicken Farmer ()
Ranch Hand
Joined: May 08, 2001
Posts: 1932
posted
0
Thanks Jim! Always just use public or private for the constructors, so entering new territory. Never sat down and read through the JLS, I think I know what I am doing this weekend Jason
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
Sounds like a long weekend. I've never read it all the way through - I just refer to it whenever I need an authoritative answer on something. Enjoy...