[자바질문] 상속하려는데요~ 오류 나네요;;
Soeun
이부분은 Car 상위 클래스이구요..
public class Car //클래스 Car
{
int velocity; //속도 인스턴스 변수
int wheelNum; //바퀴의 숫자 인스턴스 변수
String carName;//차이름 인스턴스 변수
Car(int speed, String name) //생성자
{
velocity = speed;
carName = name;
}
Car(int speed,int wheel, String name) //생성자 오버로딩
{
velocity = speed;
wheelNum = wheel;
carName = name;
}
void Booster() //부스터 메서드
{
int orginasp = velocity;
velocity += 150;
System.out.println(carName+ 의 부스터! 속도: +velocity);
velocity = orginasp;
}
void SpeedUp()
{
velocity++;
}
void SpeedUp(int speed)
{
velocity = speed;
}
void SpeedDown()
{
velocity--;
}
/*public static void main(String args[])
{
Car myCar = new Car(10,EF 소나타);
Car yourCar = new Car(150,4,Encho Ferrari);
myCar.Booster();
myCar.SpeedUp(300);
myCar.SpeedDown();
System.out.println(myCar.carName+ 의 속도는+myCar.velocity);
System.out.println();
yourCar.SpeedUp();
yourCar.Booster();
System.out.print(yourCar.carName+ 의 속도는 +yourCar.velocity);
System.out.println( 이며 바퀴의 숫자는+yourCar.wheelNum);
}*/
}
여기는 새로정의한 ColorCar 하위 클래스 입니다.
class ColorCar extends Car
{
String carColor;
ColorCar(int speed, int wheel, String name, String color) //오류나는 부분
{
velocity = speed;
wheelNum = wheel;
carName = name;
carColor = color;
}
public static void main(String args[])
{
ColorCar myNew_Car = new ColorCar(135,4,Macralen F1,Black);
myNew_Car.SpeedUp();
myNew_Car.Booster();
System.out.println(myNew_Car.carName+ 의 속도 : +myNew_Car.velocity);
System.out.println(바퀴의 숫자 : +myNew_Car.wheelNum+ 색깔 : +myNew_Car.carColor);
}
}---------- 컴파일러 ----------
ColorCar.java:6: cannot resolve symbol
symbol : constructor Car ()
location: class Car
{
^
1 error
출력 완료 (0초 경과) - 정상 종료
이런 오류 뜨는데요 상위Car클래스를 같은 폴더에 넣고, 접근제어자도 public으로 해놨는데도 말썽이네요.
-
큰돛
생성자~!
-
지우개
Car 클래스에 디폴트 생성자가 없기때문에 명시적으로 호출해줘야 합니다.
ColorCar(int speed, int wheel, String name, String color) //오류나는 부분
{
velocity = speed;
wheelNum = wheel;
carName = name;
carColor = color;
}
이부분을
ColorCar(int speed, int wheel, String name, String color)