This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner class" Watch "Inner class" New topic
Author

Inner class

RajeshParab
Greenhorn

Joined: Feb 08, 2000
Posts: 14
<PRE>
class Outer { // outer class
void test() {
final int outer_x = 100;
public class Inner { // Inner class
void display() {
System.out.println("display: outer_x =" + outer_x);
}
}
Inner inner = new Inner();
inner.display();
}
}
class Parent {
public static void main(String args[]) {
Outer outer = new Outer();
System.out.println(outer.toString());
outer.test();
}
}
</PRE>
I am getting compilation error for above code. but if i remove public modifier from inner class. It is working fine. and i am getting proper result. Can any body help me here???
?? Can i use any other modifier for inner class for ex. in above ex. its working fine for default modifier but not for other modifiers.
?? Is there any way to instantiate inner class out of Outer class. For ex. In above ex. can i use Inner class reference in Parent class. (other that static)
------------------
[This message has been edited by Tony Alicea (edited February 20, 2000).]
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
Local inner classes cannot be public.
You have a local inner class and not just an inner class.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
BTW, local classes are classes defined inside methods.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inner class
 
Similar Threads
Nested Classes
Inner Classes...
Question about top-level nested class/static inner class
Anonymous Inner Class Flavour 1 Question
Inner Class