时间:2022-09-14 09:14:57 | 栏目:JAVA代码 | 点击:次
TestCar.java
class Car {
String color;
String brand;
void run() {
System.out.printf("I am running...running..running~~~~\n");
}
void showMessage() {
System.out.printf("汽车颜色:%s, 汽车品牌:%s\n", color, brand);
}
}
改进后的TestCar_EX.java
class Car {
String color;
String brand;
public Car(String color, String brand) {
this.color = color; //这里的this是这个对象的意思.第一个color是这个对象的color属性,第二个是局部变量color
this.brand = brand; //同上
}
void run() {
System.out.printf("I am running...running..running~~~~\n");
}
void showMessage() {
System.out.printf("汽车颜色:%s, 汽车品牌:%s\n", color, brand);
}
}