请问构造器的名称必须与当前所在类的名称相同,但为什么TestCar_EX这个类中可以有Car这个名称的构造器?
public class TestCar_EX {
public static void main(String[] args) {
Car c1 = new Car("red", "xxx");
}
}
class Car {
String color;
String brand;
public Car(String color, String brand) {
this.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);
}
}
添加回答
举报
0/150
提交
取消