0
Nested classes in java.
How can we access instance data member inside static nested class ?
4 Answers
+ 1
Okkkkkay thanks
0
Like this
public class Main {
int a=10;
static class Test {
static int val = 10;
int Y = 5;
System.out.println(a);
}
public static void main(String[] args) {
System.out.println(Test.val);
}
}
If you want to create an instance of static class then
Main.Test T = new Main.Test();
System.out.println(T.Y);
you can access member "val" also like T.val but prefer accessing static member through static context i.e through class name Test.val
How can we access the value of a ?