Inheritance and Subclasses
I am trying to solve this exercise I am doing.
Basically I need to create a , class ( I already did) that has 3 instance variables (
double horsepower, aerodynamics, weight
In this class as well I did the following
Then I created a subclass of Vehicle called SportCar (I extended the class)
public class Vehicle
private double horsepower, aerodynamics, weight;
public Vehicle(double initialHorsepower, double initialAerodynamics, double initialWeight)
// initialise instance variables
horsepower = initialHorsepower;
aerodynamics = initialAerodynamics;
weight = initialWeight;
public double getHorsepower()
public double getAerodynamics()
public double getWeight()
it has an additional variable in it )All sportcars have aerodynamics = 0.5
I need to create 3 sportcars which have the following:
public class SportCar extends Vehicle
public double topspeed;
public SportCar(double initialHorsepower, double initialAerodynamics, double initialWeight)
public double getTopspeed()
SportCar1 : horsepower = 200, weight = 1500, topspeed = 220
SportCar2 : horsepower = 100, weight = 1000, topspeed = 170
SportCar3 : horsepower = 135, weight = 1100.2, topspeed = 173
So I created them in another class called TestConsumption
my problems are:
public class TestConsumption
public static void main(String args)
SportCar SportCar1 = new SportCar();
SportCar SportCar2 = new SportCar();
SportCar SportCar3 = new SportCar();
How do I create 3 instances of sportcar/initialize the horsepowers, weights and topspeeds for all the sportcars?
Is my method of setting aerodynamic =0.5 for all sportcars right?
Are those codes correct. I did get a few cannot find symbol along the way.
Any help is greatly appreciated.