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

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 (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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Asma and Jane, I really appreciate.
--Farooq
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic