public abstract class Car
{
private String name;
public Car(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setName()
{
this.name=name;
}
public abstract void introduce();
}
public interface Way
{
void run();
}
public class Motor extends Car implements Way{
public Motor(String name) {
super(name);
}
@Override
public void introduce()
{
System.out.println("我是"+getName());
}
@Override
public void run()
{System.out.println(getName()+"用轮子跑!");}
}
public class Boat extends Car implements Way
{
public Boat(String name) {
super(name);
}
@Override
public void introduce()
{
System.out.println("我是"+getName());
}
@Override
public void run()
{System.out.println(getName()+"用桨划!");}
}
public class Administrator1
{
private String name;
public Administrator1(String name)
{
this.name=name;
}
public void order(Motor motor)
{System.out.println(this.name+"介绍"+motor.getName());}
public void order(Boat boat)
{System.out.println(this.name+"介绍"+boat.getName());}
public String getName()
{return name;}
public void setName()
{this.name=name;}
}
class Test2
{
public static void main(String[] args)
{
Boat boat=new Boat("小船");
boat.introduce();
boat.run();
Motor motor=new Motor("哈雷摩托");
motor.introduce();
motor.run();
Administrator1 a=new Administrator1("小王");
a.order(motor);
a.order(boat);
}
}