this - System.out.println(super) in java -
this question has answer here:
- how super implemented in java? 5 answers
this in java works reference variable, super not, why? example: can system.out.println("this: " + this); can never system.out.println("super: " + super);
class base { public base() { system.out.println("base constructor"); } } class child extends base { public child() { system.out.println("child constructor"); system.out.println("this: " + this); //system.out.println("super: " + super); } } the reason think of is, when use new keyword memory allocated in heap , reference id of memory saved in this. there no memory space allocation parent in heap there no reference id stored in super.
am wrong? or there missing with. can this reference variable & super not?
yes, that's right. there's no reference id can stored in super, that's why can't print it. super keyword used access parent data members/constructor.
Comments
Post a Comment