/**抽象接口Tcatics*/
interface Tcatics
{
/**突破*/
public abstract void Einbruch();
}
/**抽象接口Application*/
interface Application
{
/**标志*/
public abstract void mark();
}
/**名字叫Tank的父类*/
public class Tank
{
/**名字*/
private String name;
/**速度*/
private int speed;
/**射程*/
private double range;
/**火力*/
private String fierpower;
/**建立空参*/
public Tank()
{
super();
}
public Tank(String name, int speed, double range, String fierpower) /**建立实参*/
{
super();
this.name = name;
this.speed = speed;
this.range = range;
this.fierpower = fierpower;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getSpeed()
{
return speed;
}
public void setSpeed(int speed)
{
this.speed = speed;
}
public double getRange()
{
return range;
}
public void setRange(double range)
{
this.range = range;
}
public String getFierpower()
{
return fierpower;
}
public void setFierpower(String fierpower)
{
this.fierpower = fierpower;
}
/**父类建立成员函数*/
public void defense()
{
System.out.println(name+"在防御");
}
/**父类建立成员函数*/
public void attack()
{
System.out.println(name+"在进攻");
}
public void show()
{
System.out.println("名字:"+name+",速度:"+speed+"(公里/小时),射程:"+range+"(米),火力:"+fierpower);
}
}
/**子类TigerKing继承父类Tank,实现接口Application,Tcatics*/
class TigerKing extends Tank implements Application,Tcatics
{
/**子类TigerKing建立空参*/
public TigerKing(){}
/**子类TigerKing建立实参*/
public TigerKing(String name, int speed, double range, String fierpower)
{
super(name, speed, range, fierpower);
}
/**子类TigerKing建立成员函数*/
public void MiliaryAction()
{
defense();
attack();
}
/**子类TigerKing建立实现interface接口*/
public void mark()
{
System.out.println("标志是卐");
}
/**子类TigerKing建立实现第二个interface接口*/
public void Einbruch()
{
System.out.println("TigerKing was Einbruching");
}
}
class Sherman extends Tank implements Application
{
/**子类Sherman建立空参*/
public Sherman(){}
/**子类Sherman建立实参*/
public Sherman(String name, int speed, double range, String fierpower)
{
super(name, speed, range, fierpower);
}
/**子类Sherman建立成员函数*/
public void MiliaryAction()
{
defense();
attack();
}
/**子类Sherman建立实现interface接口*/
public void mark()
{
System.out.println("Sherman标志是★");
}
}
class JosephStalin extends Tank implements Application
{
/**子类JosephStalin建立空参*/
public JosephStalin(){}
/**子类JosephStalin建立实参*/
public JosephStalin(String name, int speed, double range, String fierpower)
{
super(name, speed, range, fierpower);
}
/**子类JosephStalin建立成员函数*/
public void MiliaryAction()
{
attack();
defense();
}
/**子类JosephStalin建立实现interface接口*/
public void mark()
{
System.out.println("JosephStalin标志是Ж");
}
}
class Tanktext
{
public static void main(String[] args)
{
/**抽象接口多态*/
Tcatics tk = new TigerKing();
/**抽象接口多态*/
Application tk1 = new TigerKing();
/**TigerKing建立对象,调用父类属性*/
TigerKing t = new TigerKing();
t.setName("TigerKing");
t.setSpeed(90);
t.setRange(4500);
t.setFierpower("非常强");
/**t对象调用子类函数*/
tk.Einbruch();
tk1.mark();
t.show();
t.MiliaryAction();
System.out.println("------------------------------------");
/**抽象接口多态*/
Application tk2 = new Sherman();
/**Sherman建立对象,调用父类属性*/
Sherman s = new Sherman();
s.setName("Sherman");
s.setSpeed(160);
s.setRange(1500);
s.setFierpower("稍强");
/**s对象调用子类函数*/
tk2.mark();
s.show();
s.MiliaryAction();
System.out.println("------------------------------------");
/**抽象接口多态*/
Application tk3 = new JosephStalin();
/**JosephStalin建立对象,调用父类属性*/
JosephStalin j = new JosephStalin();
j.setName("JosephStalin");
j.setSpeed(110);
j.setRange(3500);
j.setFierpower("极强");
/**j对象调用子类函数*/
tk3.mark();
j.show();
j.MiliaryAction();
}
} |
|