public interface Swim {
public abstract void swim();
}
public abstract class Animal {
public abstract void eat();
}
public class Test {
public static void main(String[] args) {
new Swim(){
@java.lang.Override
public void swim() {
System.out.println("重写了游泳的方法");
}
};
new Animal(){
@java.lang.Override
public void eat() {
System.out.println("重写了eat方法");
}
};
method(
new Animal() {
@java.lang.Override
public void eat() {
System.out.println("狗吃骨头");
}
}
);
}
public static void method(Animal a){
a.eat();
}
}
运行结果