0

Nested classes in java.

How can we access instance data member inside static nested class ?

21st Nov 2019, 6:43 AM
Sparsh Agarwal
Sparsh Agarwal - avatar
2 Réponses
+ 1
Okkkkkay thanks
21st Nov 2019, 11:09 AM
Sparsh Agarwal
Sparsh Agarwal - avatar
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 ?
21st Nov 2019, 10:56 AM
Sparsh Agarwal
Sparsh Agarwal - avatar