• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner Classes

 
Muhammad Farooq
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • 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
 
Asma Zafar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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)
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Muhammad,
Inner classes can have any of the access modifiers (public, 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
  • Quote
  • Report post to moderator
Thanks Asma and Jane, I really appreciate.
--Farooq
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic