• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic