编写程序,要求如下:
(1)定义Biology(生物)、Animal(动物)和Mankind(人)3个接口;
(2)接口Biology声明breath()抽象方法;
(3)接口Animal继承Biolog并声明move()和eat()抽象方法;
(4)接口Mankind继承Animal并声明study()和think()抽象方法;
(5)定义类NormalMan实现接口Mankind,仅显示相应的功能信息来实现它们声明的抽象方法;
(6)在类NormalMan中定义私有变量name,实现无参构造方法和有参构造方法初始化该变量。
代码如下
```javascript
// An highlighted block
package shiyan;
interface Biology {
void breath();
}
interface Animal extends Biology {
void move();
void eat();
}
interface Mankind extends Animal{
void study();
void think();
}
class NormalMan implements Mankind{
String name;
public NormalMan(){
}
public NormalMan(String name){
this.name=name;
System.out.println("我的名字是"+this.name);//输出
}
public void breath() {
System.out.println("我一边呼吸");//输出行
}
public void move() {
System.out.println("我一边移动");//输出行
}
public void eat() {
System.out.println("我一边吃东西");//输出行
}
public void study() {
System.out.println("我一边学习");//输出行
}
public void think() {
System.out.println("我一边思考");//输出行
}
}
public class Test777 {
public static void main(String[] args) {
NormalMan dxh = new NormalMan("xxx");//注释:xxx处改为名字
dxh.breath();
dxh.move();
dxh.eat();
dxh.study();
dxh.think();
}
}