• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing protected inner class with .new

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding is that inner classes are no different in terms of access modification as other class members, thus I was expecting the following to compile:



is being used over here in package B



Why can I not access the protected inner class when ClassB is inheriting it as is the case with the protected method?

thanks in advance!

[ August 08, 2008: Message edited by: Chris Jones ]
[ August 08, 2008: Message edited by: Chris Jones ]
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jones,

Your doubt is very obvious. I tried for around 45 min. to find out why the compilation is failing. Finally I got that.

The default constructor generated by compiler has same access modifier as of the class. So a protected constructor is generated which can be accessed in other packages only by classes which extend that inner class. I changed the code as below and it has compiled fine now.


Hope it clears your doubt.
 
Chris Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot for taking the time to look at it. I've also learned that it's specified in the JLS here:

http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.2
 
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic