• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Inner Classes

 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What modifiers(private, public protected, or none(default), static, final, native, abstract) can we place for inner class(member inner class, local inner class, anonymous inner class) declaration. Can inner class have constructors.
AAA.
--Farooq
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For static inner classes (Top level)
All 4 access modifiers are applicable
For non static (nested inner classes)
All 4 access modifiers are applicable
For local static inner classes (i.e inner classes within static methods)
There should'nt be any access modifier
For local inner classes (i.e inner classes within non static methods)
There should'nt be any access modifier
For anonymous inner classes (i.e anonymous inner classes within static/non static methods)
There should'nt be any access modifier
Yes, inner classes can have constructors (except anonymous ones)
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Muhammad,
Inner classes can have any of the access modifiers (coderanch, private, protected or none). They can also be final or abstract; but not both.
If a nested class is declared with the static modifier; it becomes a static member class or top-level nested class (technically, an 'inner class' is a nested class declared without the 'static' modifier)
A local inner class does not take any access modifier, it cannot be static. It can be declared abstract or final (but not both)
All of the above can be declared with the strictfp modifier.
Anonymous classes cannot be declared with any modifiers (or extends or implements clause).
None of the above can be 'native' ... that modifier only applies to methods.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Muhammad Farooq
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Asma and Jane, I really appreciate.
--Farooq
 
reply
    Bookmark Topic Watch Topic
  • New Topic