+ 1

inheritance

how can we use that "super"?

19th Jan 2017, 10:51 AM
belmahdi zakaria
belmahdi zakaria - avatar
1 ответ
0
As the _first_ statement of the constructor you can use it with brackets to call the parametrised constructor in the parent. Then you can use it in place of keyword this anywhere else to disambiguate calls to overridden superclass methods. I did a quiz on it but the mods modded out all mention of super. eg (this is in my codes if you want to see it run) class B{ int vegetables; B(int vegetables) { this.vegetables=vegetables; } void buyVeg() { System.out.print ("buying "); } } class A extends B { void buyVeg() { System.out.print ("shopping"); } A() { super(6); super.buyVeg(); } }
19th Jan 2017, 10:53 AM
Leon
Leon - avatar