public class Ttest {
public static void main(String[] args) {
Cellphone c1 = new Cellphone();
c1.naozhong(new Bell() {
@Override
public void ring() {
System.out.println("懒猪起床了");
}
});
System.out.println("++++++++++++++");
Cellphone c2 = new Cellphone();
c2.naozhong(new Bell() {
@Override
public void ring() {
System.out.println("起床上课了");
}
});
c2.naozhong(() -> {
System.out.println("Lambda表达式-->简化匿名内部类的代码写法");
});//Lambda表达式使用前提 必须是接口的匿名内部类,接口中只能有一个抽象方法
}
}
interface Bell {
void ring();
}
class Cellphone {
public void naozhong(Bell bell) {
bell.ring();
}
}
标签:练习题,Cellphone,内部,void,System,匿名,ring,public,out
From: https://www.cnblogs.com/weifengfuxiufa/p/16890404.html