23.6k views
5 votes
Write your own SportsCar class that extends the Car class. This new class should have the following unique protected instance variables: myColor, MyEngine that stores its engine size in liters, mySuspension - e.g., firm, soft, touring, etc., and myTires - e.g., regular, wide, low profile, etc. To utilize this SportsCar class, add the following lines to the Driver class. Note that the last four parameters (

User EdgeCase
by
4.5k points

1 Answer

6 votes

Answer:

class SportsCar extends Car {

protected String myColor;

protected float myEngine;

protected String mySuspension;

protected String myTires;

}

Step-by-step explanation:

With the provided information the class can be written as above.

Create a class called SportsCar. Since it extends from the Car, you need to type extends Car after the class name. This implies that it is a subclass of the Car class.

Then, declare its protected variables:

a string called myColor that will hold the color,

a float myEngine that will hold the engine size

a string mySuspension that will hold the suspension type

a string myTires that will hold the tire type

User Michael Rovinsky
by
4.7k points