接口的定义和使用
练习
public abstract class Animal {
private String name;
private int age;
public Animal() {
}
public Animal(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public abstract void eat();
}
public interface Swim {
public abstract void swim();
}
public class Rabit extends Animal{
public Rabit() {
}
public Rabit(String name, int age) {
super(name, age);
}
@Override
public void eat() {
System.out.println("兔子在吃东西");
}
}
public class Frog extends Animal implements Swim{
public Frog() {
}
public Frog(String name, int age) {
super(name, age);
}
@Override
public void eat() {
System.out.println("青蛙吃虫子");
}
@Override
public void swim() {
System.out.println("青蛙在游泳");
}
}