• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How inner class be protected

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends,
It's known to all that classes can't be protected. but how is it possible for a inner class to be protected, as it's a class anyway.
sandy
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMO inner classes are members of the containing class as are member variables or methods, so protected accessibility of inner classes is allowed. Protected for top-level classes makes no sense though.
HIH

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
sandeep bhatnagar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx a lot valentin. u just cleared my doubt.
sandy
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sandeep,
Adding to what Val said...
The classes

  • Top-Level nested classes and interfaces
  • Non-Static Inner Classes
  • Local Classes
  • Anonymous Classes

  • are called Nested classes. The first type is also considered to be at the top level. The other 3 are collectively known as inner classes.
    Not all inner classes can be protected. Only the non-static inner class can be declared protected (In fact, it can have public, protected, private or default accessibility).
    For the Local and Anonymous Classes, no access modifiers can be specified. This is so because they are local members of a method/block etc.,

    Hope this helps
    Shyam

    [This message has been edited by Shyamsundar Gururaj (edited October 22, 2001).]
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Kaushal,
I have created a chart of all the variables that can be used with inner classes and it is available here.
Regards
Gurpreet Sachdeva
For Mock Exams, FAQ and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: http://www.go4java.20m.com
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic