• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

A basic concept

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all;
What does the following sentence mean?
"Member inner classes can be forward referenced.Local inner classes cannot be."
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This means that references to a member inner class, like any member variable, can occur before the definition of the inner class in the program. However, the same is not true for local inner classes(local inner classes, like local variables, are those that are defined inside a method).
 
Anon Ning
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sanjeev!But could you please give me a example to help me understand it further.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre>
public class Test {
class Inner {
//do inner stuff This is a member class
}
public void sampleMethod() {
class InMethodClass{
//do local inner class stuff.
}
}
}
</pre>
Because the InMethodClass in inside a method that will not last forever, the conditions for creating that class are special. For instance it can not use the local variables of the enclosing method unless they are final variables. This is because local variables die when the method is over, but objects live on until they no longer have a reference. They can't use a variable that is already dead. Final variables get created in the Constant Pool and don't die.
 
Anon Ning
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cindy! I got it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic