创建Employee和 Developer 接口,在 Employee中添加 work()方法,在Developer中添加code()方法,在 Person类中实现这两个方法,输出“我在工作”和“我在编码”;修改Person类,不仅能继承Human类的吃饭eat()、走路walk()外,还可以实现Employee和Developer的接口。
interface Employee{
void work();
}
interface Developer{
void code();
}
abstract class Human{
public abstract void eat();
public abstract void walk();
}
class Person implements Human{
public void code(){
System.out.println("我在编码");
}
public void work(){
System.out.println("我在工作");
}
public void eat(){
System.out.println("人需要进食");
}
public void walk(){
System.out.println("人会走路");
}
}
implements
package test;
public class TestInterface {
public static void main(String[] args) {
Person person = new Person();
person.code();
person.eat();
person.work();
person.walk();
}
}
interface Employee {
void work();
}
interface Developer {
void code();
}
class Person extends Human implements Employee,Developer {
@Override
public void work() {
System.out.println("我在工作");
}
@Override
public void code() {
System.out.println("我在编码");
}
}
class Human {
public void eat() {
System.out.println("我在吃饭");
}
public void walk() {
System.out.println("我在走路");
}
}