import java.util.Random;
class VehicleConstructor{
private int startSpeed;
public VehicleConstructor() {
setSpeed();
System.out.println("VehicleConstructor");
}
private void setSpeed(){
int minSpeed = 1;
int maxSpeed = 40;
Random random = new Random();
this.startSpeed = random.nextInt(maxSpeed - minSpeed + 1) + minSpeed;
}
}
class Bicycle extends Vehicle{
public Bicycle(){
System.out.println(getSpeed());
}
}
public class Vehicle{
public static void main(String[] args){
Bicycle bicycle = new Bicycle();
}
}
问题出在Bicycle
课堂上,我尝试getSpeed()
从课堂上调用方法VehicleConstructor
。我也用this
and试过了super
。怎么了?