-
Notifications
You must be signed in to change notification settings - Fork 0
Class
Keyhan Hadjari edited this page Sep 17, 2016
·
1 revision
- Subclass call superclass constructor by super(xxx)
- The identifier super(xxx) has to be the first line in subclass constructor
- The subclass constructor has to call at least one of the superclass constructors, default constructor is only allowed if superclass has a no argument constructor or default constructor.
public class Vehicle {
protected int numberOfWheels;
protected int numberOfPassengers;
public Vehicle(int nWheels, nPassengers) {
}
}
public class Motorcycle extends Vehicle{
public Motorcycle(EngineType type) {
super(2,2);
.
.
}
}
public class Minivan extends Vehicle{
public Minivan(String brand) {
super(4,7);
.
.
}
}