java接口多实现和多继承

时间:2023-12-30 23:42:32
package test;
interface mouth {
public abstract void speak();
}
interface nose{
public abstract void smell();
}
interface eye{
public abstract void look();
}
interface ear{
public abstract void listen();
}
interface brain{
public abstract void think();
}
interface head extends mouth,nose,eye,ear,brain { }
class myHead implements head {
public void speak() {
System.out.println("I can speak");
}
public void smell() {
System.out.println("I can smell");
}
public void look() {
System.out.println("I can see");
}
public void listen() {
System.out.println("I can listen");
}
public void think() {
System.out.println("I can think");
}
}
class yourHead implements mouth,nose,eye,ear,brain {
public void speak() {
System.out.println("you can speak");
}
public void smell() {
System.out.println("you can smell");
}
public void look() {
System.out.println("you can see");
}
public void listen() {
System.out.println("you can listen");
}
public void think() {
System.out.println("you can think");
}
}
public class InterfaceTest { public static void main(String[] args) {
myHead myHead = new myHead();
myHead.speak();
myHead.smell();
myHead.listen();
myHead.look();
myHead.think();
yourHead yourHead = new yourHead();
yourHead.speak();
yourHead.smell();
yourHead.listen();
yourHead.look();
yourHead.think();
} }
I can speak
I can smell
I can listen
I can see
I can think
you can speak
you can smell
you can listen
you can see
you can think