java作业整理

题意:

1. 声明一个狮子类(Lion)继承自食肉动物类(Carnivore),并且实现Runnable接口。

要求:(1) 写出Runnable接口,并定义一个返回值为空的方法run()

      (2) 写出Carnivore类,定义为抽象,封装一属性 int legs;写出含有参数int legs的构造方法;封装一抽象方法名为getWeight(),返回类型为int

      (3)  写出Lion类,复写父类与接口中的方法,仅输出提示信息即可。

public interface Runnable {
   public abstract String run();
}




public abstract class Carnivore {
      private int legs;
      
      public Carnivore(int legs){
    	  this.legs = legs;
      }

	public int getLegs() {
		return legs;
	}

	public void setLegs(int legs) {
		this.legs = legs;
	}
    public abstract int getWeight();
}


class Lion extends Carnivore implements Runnable{

	public Lion(int legs) {
		super(legs);
	}

	public int getWeight() {
		return 0;
	}

	public String run() {
		return null;
	}

}

你可能感兴趣的:(java作业整理)