java——20171121
文章目录








in method //main函数开始,创建了IA类型的对象,运行Myclass中method方法,打印in method
ma in anonymous inner class //运行new IA()中的ma()方法
in method // 再次运行MyClass中method方法
ma in local inner class //运行MyMaClass中的ma方法

选ABC
D因为stu1 与 100之间为运算符,所以stu1无法转化成int类型 所以不选

interface Light {
void shine();
}
class Lamp {
public void on(Light light) {
light.shine();
}
}
public class TestLamp {
public static void main(String args[]) {
Lamp lamp = new Lamp();
// 局部内部类
class JuBuInner implements Light {
@Override
public void shine() {
System.out.println("shine in red");
}
}
lamp.on(new JuBuInner());
//匿名内部类
lamp.on(new Light(){
public void shine(){
System.out.println("shine in yellow");
}
});
}
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册⭐️ Admin快速开发: https://show.cool-admin.com/
赞 0⭐️ 官方文档: https://cool-js.com
赞 0⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld
赞 0