aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner Classes" Watch "Inner Classes" New topic
Author

Inner Classes

Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
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


Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Asma Zafar
Ranch Hand

Joined: May 11, 2001
Posts: 49
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)


Asma Zafar,<BR>Sun Certified Programmer for Java2 Platform
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
Thanks Asma and Jane, I really appreciate.
--Farooq
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inner Classes
 
Similar Threads
doubt on Inner class
Inner Classes
Innner Class
Inner Classes
is inner class can be static . what is the purpose of inner class ??