package demo3;
import java.awt.*;
class Animal{
public String name;
public Animal(String name){
this.name = name;
}
public void eat(){
System.out.println(this.name + "正在吃饭");
}
}
interface IFlying{
void fly();
}
interface IRunning{
void run();
}
interface ISwimming{
void swim();
}
class Cat extends Animal implements IRunning{
public Cat(String name) {
super(name);
}
@Override
public void run() {
System.out.println(this.name + "is cat 正在跑");
}
}
class Dog extends Animal implements IRunning, ISwimming{
public Dog(String name) {
super(name);
}
@Override
public void run() {
System.out.println(this.name + "is dog正在跑");
}
@Override
public void swim() {
System.out.println(this.name + "正在游泳");
}
}
class Robot implements IRunning{
@Override
public void run() {
System.out.println("机器人正在跑");
}
}
class Duck extends Animal implements IRunning, ISwimming, IFlying{
public Duck(String name) {
super(name);
}
@Override
public void fly() {
System.out.println(this.name + "fly");
}
@Override
public void run() {
System.out.println(this.name + "run");
}
@Override
public void swim() {
System.out.println(this.name + "swim");
}
}
public class Test2 {
public static void walk(IRunning iRunning){
iRunning.run();
}
public static void swim(ISwimming iSwimming){
iSwimming.swim();
}
public static void fly(IFlying iFlying){
iFlying.fly();
}
public static void main(String[] args) {
Duck duck = new Duck("tanglaoya");
swim(duck);
fly(duck);
walk(duck);
}
public static void main2(String[] args) {
Dog dog = new Dog("哈哈");
walk(dog);
walk(new Dog("mimi2"));
walk(new Cat("mimi1"));
walk(new Robot());
}
public static void main1(String[] args) {
Animal animal = new Cat("mimi");
Animal animal1 = new Dog("mimi2");
IRunning iRunning = new Dog("mimi2");
ISwimming iSwimming = new Dog("mimi2");
IRunning iRunning1 = new Cat("mimi");
}
}
|