📄 anonymousinnerclassdemo.java
字号:
interface GPRS{
public void position();
}
abstract class ABS{
String type;
public ABS(String type){
this.type = type;
}
abstract public void stop();
}
class Car{
String brand;
String color;
GPRS tools;
ABS abs = new ABS("XXX"){
public void stop(){
System.out.println(type + "ABS系统使您的车停下来了");
}
};
public Car(String 牌子,String 颜色,final int miles){
brand = 牌子;
color = 颜色;
tools = new GPRS(){
public void position(){
System.out.println("您的"+brand +"车已经行走了"+miles +"英里, 现在的位置是广州");
}
};
}
public void getMiles(int miles){
System.out.println("您行走了"+ miles + "英里");
}
public void show(){
System.out.println("这是一辆"+ color +brand +"车");
tools.position();
abs.stop();
}
}
public class AnonymousInnerClassDemo{
public static void main(String arg[]){
Car 捷达 = new Car("捷达","黑色",50000);
捷达.show();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -