使用文字和图画描述,如下程序的执行过程:
public class TestObject {
public static void main(String[] args) {
Car c1 = new Car();
c1.changeColor("红色");
c1.showColor();
System.out.println(Car.tyreNum);
System.out.println(c1.tyreNum);
Car c2 = new Car();
Engine e = new Engine();
e.speed = 1000;
e.weight = 10;
c2.engine = e;
c2.color = "黑色";
c2.tyreNum = 10;
System.out.println(c1.tyreNum);
}
}
class Car {
static int tyreNum = 4;
Engine engine;
String color; // char sequence :字符序列
void changeColor(String c) {
color = c;
}
void showColor() {
System.out.println("我的颜色是:" + color);
}
}
class Engine {
int speed;
int weight;
}