Scope and use of super keyword in Java -
why can't access parent class variable super keyword?
with below code, output is:
feline cougar c c class feline { public string type = "f "; public feline() { system.out.print("feline "); } } public class cougar extends feline { public cougar() { system.out.print("cougar "); } void go() { type = "c "; system.out.print(this.type + super.type); } public static void main(string[] args) { new cougar().go(); } }
the answer original question simple: there 1 variable called type. initial value gets overwritten c. remember there 1 object, 1 variable. prashant's code creates second variable , 1 doesn't overwrite original string in parent class.
Comments
Post a Comment