0

what if I don't want to inhire the constarctor of the super class ??

http://www.sololearn.com/app/java/playground/c1xUadh6VNnh/ in code above both constarctor of super and sub class is activate...what if I want just the constarctor of sub class to excite?

9th Aug 2016, 5:57 PM
Islam Elzohary
Islam Elzohary - avatar
2 Respuestas
0
maybe if you use an abstrackt construktor but this might be only possible for interfaces. Since this is the Concept of extends you cant do anything about this. since it wouldnt be possible to downcast it later since no construckor of this layer would have been called.
9th Aug 2016, 7:00 PM
Eric Zeus
Eric Zeus - avatar
0
class A { public A() { System.out.println("New A"); } public A(int x){ //do nothing; } } class B extends A { public B() { super(1); //useless "1", second // constructor is used System.out.println("New B"); } } class Program { public static void main(String[ ] args) { B obj = new B(); } } /* Output: New B locks dirty but it works. Maybe avoid it. */
25th Aug 2016, 9:06 PM
La Ha
La Ha - avatar