类和对象内存图示

public class 类和对象 {
	public static void main(String[] args) {
		// 对象是实体——创建对象
		Car car = new Car();
		car.color = "白色";
		car.start();
	}
}
// 类是一个概念——定义类
class Car {
	// 成员变量:属性
	String color;
	// 成员方法:行为(注:成员方法没有static关键字)
	void start() {
		System.out.println(color + "汽车启动");
	}
}


posted @ 2019-04-13 17:18  虎老狮  阅读(343)  评论(0编辑  收藏  举报