testmix.java

来自「主要是对于JAVA的编程的基本语言 希望能够帮得上你。」· Java 代码 · 共 80 行

JAVA
80
字号
package Inheritance;

/*
 * 继承与实现的混合
 */

interface Flyer {
	void takeOff();
	void land();
	void fly();
}

interface Magic{
	void change();
}

//接口可以继承多个接口
interface FlyerMagic extends Flyer,Magic{
	
}

class Airplane implements Flyer{

	public void fly() {		
		System.out.println("The airplane is flying.");
	}

	public void land() {
		System.out.println("The airplane is landing.");
	}

	public void takeOff() {		
		System.out.println("The airplane is taking off.");
	}	
}

abstract class Animal{
	abstract void eat();
}

class Superman extends Animal implements Flyer,Magic{

	public void fly() {	
		System.out.println("The superman is flying.");
	}

	public void land() {		
		System.out.println("The superman is landing.");
	}

	public void takeOff() {		
		System.out.println("The superman is taking off.");
	}	
	
	public void eat(){
		System.out.println("The superman is eating.");
	}

	public void change() {
		System.out.println("The superman is changing.");		
	}
}

public class TestMix {

	public static void main(String[] args) {		 
		Superman s=new Superman();
		s.eat();
		s.fly();
		s.land();
		s.takeOff();
		s.change();
		
		Airplane a=new Airplane();
		a.fly();
		a.land();
		a.takeOff();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?