• 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

local inner class no outer class instance?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.jaworski.com/java/certification/
said that local inner classes are not associated with an outer class instance (the applet is random so i cannot give a number).
i think local inner class instances must have associated outer classes instances. maybe it is the ambiguity of the matter. (classes of course have not outer class instance, it is the instances that have or have not associated outer instance), otherwise it does not make sense that they can access outer instance member variables.
anyone else has similar thoughts after taking his samples (which are mostly clear)?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An instance of a local inner class can be created without creating an instance of the outer class.
An instance of a member inner class can not be created without creating an instance of the outer class.
look at the following example.

class Outer {
void method() {
class Inner {
int i=10;
}
Inner inner1=new Inner();
System.out.println(inner1.i);

}
}

But to call the method void method() you to need to create an instance of the outer class like this,

Outer o=new Outer();
o.method();

I think when jamie says "not associated with the outer class", he means "can be created without the instance of the outer class" (unlike the member inner class).
Do I make any sense ?
 
john shen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, that is now perfectly clear. thanks for clear it up! i guess i was just confused by the wording then. i was thinking about using, not creating, when i read the question.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic