Here is my class:
public class T {
public int num = 100;
private int num2 = -1;
//inner class
public static class Inner {
private int num2 = 250;
public void method() {
System.out.println(num2);//calls inner class num
System.out.println(...);//should print class T num
System.out.println(...);//should print class T num2
}
}
}
How do I make second and third println to print num and num2 of class T?
You can’t – your
Innerclass is not an inner class, it is a static nested class. In other words it lives by itself without a reference to an instance of T.If you remove the
staticpart of yourInnerdeclaration, it will be possible: