Unresolved compilation problem. 다른 클래스를 참조해서. 메인에서 사용하려고 하는데 오류가났다'.
class Car {
String color; // 색상
String gearType; // 변속기 종류 - auto(자동), manual(수동)
int door; // 문의 개수
Car() {}
-----------------------------------------------------------------------
Car(String c, String g, int d) { // 이 생성자가 없다면 나는 오류. (매개변수가 있는 생성자로서, Car인스턴스 생성시 생성할 때마다 쓸 수 있도록 이렇게 매개변수 있는 생성자를 만들어 준것인데... 이게 없다면 초기화가 안되서 main에서 Car c2처럼 시작부터 원하는 값으로의 인스턴스 생성이 불가능하다.(c1 처럼 인스턴스 생성하는 것은 가능)
color = c;
gearType = g;
door = d;
}
}
--------------------------------------------------------------------
public class EEx24_1017 {
public static void main(String[] args) {
Car c1 = new Car();
c1.color = "white";
c1.gearType = "auto";
c1.door = 4;
Car c2 = new Car("White", "auto", 4);
System.out.println("c1의 color=" + c1.color + ", gearType=" + c1.gearType+ ", door="+c1.door );
System.out.println("c2의 color=" + c2.color + ", gearType=" + c2.gearType+ ", door="+c2.door );
}
}
'📟java' 카테고리의 다른 글
JAVA 2달차 점검 (1) | 2022.10.20 |
---|---|
생성자와 메서드의 구분 (0) | 2022.10.18 |
프로그래밍 수정 method <init>()V not found (0) | 2022.10.11 |