instanceinnerclassdemo.java

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

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

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

	public void show(){
		System.out.println("这是一辆"+ color +brand +"车,启动该车");
		engine.start();
	}
	
	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 InstanceInnerClassDemo{
	public static void main(String arg[]){
		Car 捷达 = new Car("捷达","黑色");
		Car.Engine 大众 = 捷达.new Engine("大众",600);
		捷达.show();
		大众.start();
		
	}
}

⌨️ 快捷键说明

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