0

use of super to access static member

https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#d5e12815 they use super to access static member how is this possible? https://code.sololearn.com/ce7e9TNonRJC/?ref=app

29th Sep 2019, 1:03 PM
Sheraz Tariq
Sheraz Tariq - avatar
2 Respostas
+ 3
Program is child class and Program1 is super class. x in Program1 is static. You don't need to create an object. Program1.x is enough. And because Program1 is the super class of program you can also write super.x The method printX() is non static. You need to create an object to call it: new Program.printX();
29th Sep 2019, 2:14 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Yea that's fine you have created a object of sub class and you accessing the the static field in parent class using super becuase you extend its fields which means theres a copy of that field in sub class so both x or super.x refer to the same x
29th Sep 2019, 2:16 PM
D_Stark
D_Stark - avatar