class D_day09作业 { //运行时间长短测试类//主类
public static void main(String[] args) {
long a =System.currentTimeMillis();
TimeInterface_Zi t = new TimeInterface_Zi();
t.ceShiChengXu();
long b=System.currentTimeMillis();
System.out.println(b-a);
}
}
interface TimeInterface{ //测试时间长短接口
public void ceShiChengXu();
}
class TimeInterface_Zi implements TimeInterface{ //子类继承接口
public TimeInterface_Zi(){}
public void ceShiChengXu(){
new AnimalInterFaceTest().Animal_InterFace_Test();
}
}
class AnimalInterFaceTest { //被运行时间长短类TimeTest调用
public static void Animal_InterFace_Test() {
System.out.println("Hello this is my world!");
JumpAndFlyCat jafc = new JumpAndFlyCat("加菲","黄色",8,4);
jafc.play();
jafc.jump();
jafc.fly();
JumpAndFlyCat.sleep();
System.out.println("--------------------------------");
JumpAndFlyDog jafd = new JumpAndFlyDog("mojo","yellow",2,4);
jafd.play();
jafd.jump();
jafd.fly();
JumpAndFlyDog.kenGuTou();
}
}
abstract class Animal{ //动物类,记录共同属性和行为
private String name;
private String color;
private int age;
private int leg;
public Animal(){} //无参构造
public Animal(String name,String color,int age,int leg){ //有参构造
this.name = name;
this.color= color;
this.age = age;
this.leg = leg;
}
public void setName(String name){ //设置姓名
this.name = name;
}
public String getName(){ //获取姓名
return name;
}
public void setColor(String color){ //设置颜色
this.color = color;
}
public String getColor(){ //获取颜色
return color;
}
public void setAge(int age){ //设置年龄
this.age = age;
}
public int getAge(){ //获取年龄
return age;
}
public void setLeg(int leg){ //设置腿数
this.leg = leg;
}
public int getLeg(){ //获取腿数
return leg;
}
public abstract void eat(); //动物的吃,,,抽象方法
public void play(){ //Animal play方法
System.out.println("我是:"+name+",我的颜色是:"+color+",我的年龄是:"+age+",我有"+leg+"条腿.");
}
}
interface AnimalJumpAndFly{ //接口,,jump和fly
public abstract void jump();
public abstract void fly();
}
class Cat extends Animal{ //猫类继承动物类
public Cat(){}
public Cat(String name,String color,int age,int leg){ //猫类的有参构造
super(name,color,age,leg);
}
public void eat(){ //猫类重写父类动物类的eat()方法
System.out.println("我是瞄,我吃鱼...");
}
}
class Dog extends Animal{ //狗类继承动物类
public Dog(){}
public Dog(String name,String color,int age,int leg){ //狗类带参构造
super(name,color,age,leg);
}
public void eat(){ //狗类重写父类动物类的eat()方法
System.out.println("我是汪,我吃肉...");
}
}
class JumpAndFlyCat extends Cat implements AnimalJumpAndFly{ //JumpAndFlyCat继承猫类,并且实现接口AnimalJumpAndFly
public JumpAndFlyCat(){}
public JumpAndFlyCat(String name,String color,int age,int leg){ //JumpAndFlyCat带参构造
super(name,color,age,leg);
}
public static void sleep(){ //JumpAndFlyCat类特有方法
System.out.println("瞄,睡得香...");
}
public void jump(){ //JumpAndFlyCat类重写接口的抽象方法jump()
System.out.println("I can jump...");
}
public void fly(){ //JumpAndFlyCat类重写接口的抽象方法fly()
System.out.println("I can fly...");
}
}
class JumpAndFlyDog extends Dog implements AnimalJumpAndFly{ //JumpAndFlyDog类继承狗类,并且实现接口AnimalJumpAndFly
public JumpAndFlyDog(){}
public JumpAndFlyDog(String name,String color,int age,int leg){ //带参构造
super(name,color,age,leg);
}
public static void kenGuTou(){ //JumpAndFlyDog类特有方法
System.out.println("汪,啃骨头...");
}
public void jump(){ //JumpAndFlyDog类重写接口类的抽象方法jump()
System.out.println("I can jump...");
}
public void fly(){ //JumpAndFlyDog类重写接口类的抽象方法fly()
System.out.println("I can fly...");
}
} |
|