Answer the question
In order to leave comments, you need to log in
Where can inheritance be applied in Java here?
We need help, we were given a task to refactor this code, we need to apply inheritance. We have a subject area car dealership.
public class Car {
public String name;
public String bodyType;
public int price;
public String toString() {
return name + "(" + bodyType + ")" + " - " + price + "$";
}
}
class HeavyCarInitializator extends Car {
public static String[] names = {
"DAF XF 105", "Volvo FH16", "Renault Magnum", "Mercedes Actros", "Scania S500", "ЗИЛ 157", "МАЗ 2021"};
private static final int[] price = {30000, 100000, 65000, 80000, 90000, 15000, 19000};
public static final String[] bodyType = {"Mixer","Truck","Garbage","Crane","Garbage","Crane","Truck"};
public static void init(Car[] HeavyCars) {
for (int i = 0; i < HeavyCars.length; i++) {
HeavyCars[i].name = names[i];
HeavyCars[i].price = price[i];
HeavyCars[i].bodyType = bodyType[i];
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question