public abstract class Transport {
abstract void distance();
public static void main(String[] args) {
// TODO Auto-generated method stub
Car QQ=new Car();
QQ.getInfo("奇瑞",80,1.5f);
QQ.distance();
Train G=new Train();
G.getInfo("G7023",380,1.5f);
G.distance();
}
}
class Car extends Transport{
String type;
float time;
int speed;
float s;
void getInfo(String type,int speed,float time)
{
this.type=type;
this.time=time;
this.speed=speed;
}
void distance()
{
s=speed*time;
System.out.println("汽车的型号:"+type);
System.out.println("汽车以时速"+speed+"千米/小时行驶了"+time+"小时,行驶的路程:"+s+"千米");
}
}
class Train extends Transport{
String number;
float time;
int speed;
float s;
void getInfo(String number,int speed,float time)
{
this.number=number;
this.time=time;
this.speed=speed;
}
void distance()
{
s=speed*time;
System.out.println("火车的车次:"+number);
System.out.println("火车的以时速"+speed+"千米/小时行驶了"+time+"小时,行驶的路程:"+s+"千米");
}
}
速度与激情
最新推荐文章于 2022-09-25 22:57:08 发布