P
P
pyps_trsh2021-05-31 13:34:33
Java
pyps_trsh, 2021-05-31 13:34:33

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

1 answer(s)
T
Therapyx, 2021-05-31
@Therapyx

Car dealership --> Cars --> Type of cars --> additional functions for these types of cars
Specifically, in this task, only cars can be divided into types of cars.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question