作业帮 > 综合 > 作业

完成生物、动物、人三个接口的定义.其中生物接口定义呼吸抽象方法,动物接口除具备生物接口特征之外

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 21:06:23
完成生物、动物、人三个接口的定义.其中生物接口定义呼吸抽象方法,动物接口除具备生物接口特征之外
还定义了吃饭和睡觉两个抽象方法.人接口除具备动物接口特征之外,还定义了思维和学习两个抽象方法,定义一个学生类,有一个名字属性,要求实现上述人接口.
public class TestInterface {

public static void main(String[] args) {
students s = new students();
s.breathe();
s.eat();
s.sleep();
s.study();
s.think();

}
}
interface LivingBeings{
void breathe();
}
interface Animals extends LivingBeings{
void breathe();
void eat();
void sleep();
}
interface Persons extends Animals{
void breathe();
void eat();
void sleep();
void think();
void study();
}
class students implements Persons{
String name;
public void breathe(){
System.out.println("人要呼吸");
}
public void eat(){
System.out.println("人要吃饭");
}
public void sleep(){
System.out.println("人要睡觉");
}
public void think(){
System.out.println("人会思考");
}
public void study(){
System.out.println("人会学习");
}
}