函数的例题

package com;

public class Demo02 {
	public static void main(String[] args) {
		Dog dog = new Dog();
		dog.eat();
		Feeder feeder = new Feeder();
		feeder.feed(dog);
	}
}

class Aniaml {
	int age;
	
	public void drink() {
		System.out.println("喝奶");
	}
	
	public void eat() {
		System.out.println("吃肉");
	}
	
	public void swim() {
		System.out.println("游泳");
	}
}

class Dog {
	public void eat() {
		System.out.println("吃骨头");
	}
	public void swim() {
		System.out.println("狗刨");
	}
}

class Feeder {
	public void feed(Dog dog) {
		dog.eat();
	}
}

上一篇:Java学习Day18


下一篇:软件设计⑧|适配器模式