MyInterface 接口
public interface MyInterface {
void method1();
void method2();
}
MyInterfaceImpl 类
public class MyInterfaceImpl implements MyInterface {
@Override
public void method1() {
System.out.println("实现类覆盖重写了方法111");
}
@Override
public void method2() {
System.out.println("实现类覆盖重写了方法222");
}
}
DemoMain
public class DemoMain {
public static void main(String[] args) {
MyInterface objA = new MyInterface() {
@Override
public void method1() {
System.out.println("匿名内部类实现了方法111-A");
}
@Override
public void method2() {
System.out.println("匿名内部类实现了方法222-A");
}
};
objA.method1();
objA.method2();
MyInterface objB = new MyInterface() {
@Override
public void method1() {
System.out.println("匿名内部类实现了方法111-B");
}
@Override
public void method2() {
System.out.println("匿名内部类实现了方法222-B");
}
};
objB.method1();
objB.method2();
}
}