my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A basic concept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A basic concept" Watch "A basic concept" New topic

A basic concept

Anon Ning

Joined: Mar 09, 2001
Posts: 19
hi all;
What does the following sentence mean?
"Member inner classes can be forward referenced.Local inner classes cannot be."
Sanjeev Gupta

Joined: Mar 08, 2001
Posts: 15
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

Joined: Mar 09, 2001
Posts: 19
Thanks Sanjeev!But could you please give me a example to help me understand it further.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
public class Test {
class Inner {
//do inner stuff This is a member class
public void sampleMethod() {
class InMethodClass{
//do local inner class stuff.
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.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Anon Ning

Joined: Mar 09, 2001
Posts: 19
Thanks Cindy! I got it.
I agree. Here's the link:
subject: A basic concept
Similar Threads
What is a class file with $ symbol in the name
Most Difficult Part?
Re:inner classes
Native Method
Why final keyword is accepted with private?