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

Inner class

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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).]
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Local inner classes cannot be public.
You have a local inner class and not just an inner class.
 
Tony Alicea
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, local classes are classes defined inside methods.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic