Extends Demo
package
demo.extend;
class Vehicle {
String type = "4w";
int maxSpeed = 100;
Vehicle(){
System.out.println("this is a father construtor");
}
Vehicle(String type, int maxSpeed){
this.type = type;
this.maxSpeed = maxSpeed;
System.out.println("this is another father construtor");
}
}
package
demo.extend;
class
Car extends Vehicle {
private String trans;
Car(String trans) {
this.trans = trans;
System.out.println("this is a son constructor");
}
Car(String type, int maxSpeed, String trans) {
super(type, maxSpeed);
// this(trans);
this.trans = trans;
// this.type = type;
// this.maxSpeed = maxSpeed;
System.out.println("this is another son constructor");
}
public static void main(String[] args) {
Car c1 = new Car("Auto");
Car c2 = new Car("4w", 150, "Manual");
System.out.println(c1.type + " " + c1.maxSpeed + " " + c1.trans);
System.out.println(c2.type + " " + c2.maxSpeed + " " + c2.trans);
}
}