How can I overide the parent class constructor?
This may be bad practice but I still want to learn how to do this.
I would like to override my parent class constructor. But as this code turns out, Truck displays the parent class constructor.
How can I accomplish overriding the parent class constructor? And if this is bad practice let me know, but I would still like to know if this is possible.
Code:
public class Vehicle {
Vehicle() {
System.out.println("I'm a vehicle");
}
}
class Car extends Vehicle {
Car() {
super();
System.out.println("I'm also a CAR.");
}
}
class Truck extends Vehicle {
Truck() {
System.out.println("Please call me TRUCK only. Don't call me Vehicle!"); //
}
}
constructor could not have "return" type....as the same time java does allow methods
it is not possible to override the super class constructor ...because by default any constructor could not have "return" type....as the same time java does allow methods with out "return" types so it is impossible to override parent class constructor