anonymousinnerclassdemo.java
来自「JAVA的一些基础教程」· Java 代码 · 共 51 行
JAVA
51 行
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 + =
减小字号Ctrl + -
显示快捷键?