staticinnerclassdemo.java

来自「JAVA的一些基础教程」· Java 代码 · 共 50 行

JAVA
50
字号
class Car{
	String brand;
	String color;	
	static String type = "越野车";
	Engine engine;
	ABS abs;	

	public Car(String brand,String color){
		this.brand = brand;
		this.color = color;
		engine = new Engine("电喷",500);
		abs = new ABS();
	}

	public void show(){
		System.out.println("这是一辆"+ color +brand +"车,该车有");
		abs.introduce();
		engine.start();
	}
	private static class ABS{
		public void introduce(){
			System.out.println("ABS防死抱系统");
		}
	}
	
	static class Engine{
		String type;
		int power;
		public Engine(String type, int power){
			this.type = type;
			this.power = power;
		}
		public void start(){
			System.out.println(type + " 引擎启动了");
//			System.out.println("车的颜色是" + color);
		}
	}
}

public class StaticInnerClassDemo{
	public static void main(String arg[]){
		Car 奔驰 = new Car("奔驰","黑色");
		Car.Engine 劳斯来斯 = new Car.Engine("劳斯来斯",600);
//		Car.ABS abs = new Car.ABS();
		奔驰.show();
		劳斯来斯.start();
		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?