class test_CAR
{
public static void main(String[] args)
{
Car BMW_X7 = new BMW();
Car BENS_S8 = new BENS();
Person p=new Person();
p.show(BMW_X7);
p.show(new Car(){
//struts action 指⽰命令
public void start(){
System.out.println("上海⼤众启动");
}
public void run(){
System.out.println("运⾏");
}
public void stop(){
System.out.println("停⽌");
}
});
p.show(new Car(){
public void start(){
System.out.println("SOKDA启动");
}
public void run(){
System.out.println("SOKDA运⾏");
}
public void stop(){
System.out.println("SOKDA停⽌");
}
});
}
}
//⽤⾯向对象的思想编写类,描述汽车,宝马,奔驰车和驾驶员的关系.上海⼤众
//提⽰:宝马和奔驰继承⾃汽车类,具有启动,运⾏,停⽌的⽅法。驾驶员具
//有驾驶⽅法,可以通过驾驶⽅法驾驶各种类型的汽车。
interface Car
{
void start();
汽车类void run();
void stop();
}
class BMW implements Car
{
public void start(){
System.out.println("启动车⼦");
}
public void run(){
System.out.println("启动运⾏");
}
public void stop(){
System.out.println("启动停⽌");
}
}
class BENS implements Car
{
public void start(){ System.out.println("启动车⼦"); }
public void run(){ System.out.println("启动运⾏"); }
public void stop(){ System.out.println("启动停⽌"); }
}
class Person
{
public void show(Car c){
c.start();
c.run();
c.stop();
}
}
发布评论