/*
接口类型的方法调用,使用匿名内部类
匿名内部类:
语法定义格式:
new 抽象类/接口(){
//要重写的方法
}
*/
interface Inter1{
void fun1();
}
//class Inter1Impl implements Inter1{
// @Override
// public void fun1() {
// System.out.println("hello java");
// }
//}
class Student2{
public void show(Inter1 inter1){
inter1.fun1();
}
}
public class NiMingClassDemo2 {
public static void main(String[] args) {
Student2 student2 = new Student2();
// student2.show(new Inter1Impl());
student2.show(new Inter1(){
@Override
public void fun1(){
System.out.println("hello 数加");
}
});
student2.show(new Inter1(){
@Override
public void fun1(){
System.out.println("hello java");
}
});
// student2.show(()-> System.out.println("hello world")); // lambda表达式
}
}