package polytest;
public class Mongo {
public static void main(String[] args) {
Study study = new Study();
// UU u = new UU();
// study.Apple(u);
//和下面的输出打铃了的匿名内部类一样,匿名内部类就是给简化了
Bell p = new Bell() {
@Override
public void ring() {
System.out.println("打铃了");
}
};
study.Apple(p);
// study.Apple(new Bell() {
// @Override
// public void ring() {
// System.out.println("打铃了");
// }
// });
// study.Apple(new Bell() {
// @Override
// public void ring() {
// System.out.println("上课了");
// }
// });
}
}
//class UU implements Bell{
// @Override
// public void ring() {
// System.out.println("打铃了");
// }
//}
interface Bell {
public void ring();
}
class Study {
public void Apple(Bell bell) {
bell.ring();
}
}
Java练习(三十四)---匿名内部类练习
最新推荐文章于 2024-04-27 09:13:51 发布