java接口作业

一、选择

1.D
2.C
3.B
4.C
5.A

二、编程

package lianxi3;

/**
 * Fly接口
 * @author Administrator
 *
 */

public interface IFly {
	public void fly();
}

package lianxi3;

/**
 * 飞机类
 * @author Administrator
 *
 */

public class Plane implements IFly{

	@Override
	public void fly() {
		System.out.println("飞机在天上飞");
	}

}

package lianxi3;

/**
 * 小鸟类
 * @author Administrator
 *
 */

public class Bird implements IFly {

	@Override
	public void fly() {
		System.out.println("小鸟在天空翱翔");
	}

}

package lianxi3;

/**
 * 气球类
 * @author Administrator
 *
 */

public class Balloon implements IFly {

	@Override
	public void fly() {
		System.out.println("气球飞在天空");
	}

}

package lianxi3;

/**
 * 测试类
 * @author Administrator
 *
 */

public class Test {
	public static void main(String[] args) {
		IFly p = new Plane();
		p.fly();
		IFly b = new Bird();
		b.fly();
		IFly o = new Balloon();
		o.fly();
	}
}

你可能感兴趣的:(java接口作业)