パッケージ A にあるクラス Vehicle とパッケージ B にあるクラス Car があり、equals メソッドを使用して、super() を使用して継承を利用したいのですが、これを行う方法がわかりません。
メインでファイルを実行しようとすると、次のようになります。
Exception in thread "main" java.lang.NullPointerException
at vehicle.Vehicle.equals(Vehicle.java:97)
at car.Car.equals(Car.java:104)
at Main.main(Main.java:48)
コードは次のとおりです。
public boolean equals(Vehicle other) {
if (this.type.equals(other.type)) {
if (this.year == other.year && this.price == other.price) {
return true;
} else {
return false;
}
} else {
return false;
}
}
//equals in Car
public boolean equals(Car other) {
if (this.type.equals(other.type)) {
if (this.speed == other.speed && this.door == other.door) {
if (super.equals(other)) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}