I have this code :
public class EnclosingClass {
public int age;
public int height ;
class Job {
public String dateBegin ;
public int yearsExperience;
public void displayCompleteProfile() {
System.out.println(toString()+" age : "+age+" height : "+height);
}
@Override
public String toString() {
return "Job [dateBegin=" + dateBegin + ", yearsExperience=" + yearsExperience + "]";
}
}
@Override
public String toString() {
return "EnclosingClass [age=" + age + ", height=" + height + "]";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
EnclosingClass enClass = new EnclosingClass();
enClass.age = 20;
enClass.height = 170;
EnclosingClass.Job job1 = enClass.new Job();
job1.dateBegin = "12/12/2008";
job1.yearsExperience = 5;
job1.displayCompleteProfile();
enClass = null;
job1.displayCompleteProfile();
}
}
and when I execute the code I get this result :
Job [dateBegin=12/12/2008, yearsExperience=5] age : 20 height : 170
Job [dateBegin=12/12/2008, yearsExperience=5] age : 20 height : 170
How come my nested class object job1 still has access to it's enclosing class instance enClass attributes even after I set the object to null?