Write 3 Java classes called Car, OffroadCar and HybridCar. Demonstrate the conce
ID: 3904334 • Letter: W
Question
Write 3 Java classes called Car, OffroadCar and HybridCar. Demonstrate the concept of inheritance by making the Car class your superclass. Give it the following attributes:
int num_doors; // number of doors the car has
int hp; // the horse power of the car
boolean manual; // true if manual transmission, false if automatic
____________
OffroadCar Class
should be derived from the Car class and have the additional attribute:
int wheel_diameter; // diameter of wheel in mm.
_____________________
HybridCar
should be derived from the Car class and have the additional attribute:
int batteries; // number of batteries in the car
Explanation / Answer
public class Car { int num_doors; // number of doors the car has int hp; // the horse power of the car boolean manual; // true if manual transmission, false if automatic } class OffroadCar extends Car { int wheel_diameter; // diameter of wheel in mm. } class HybridCar extends Car { int batteries; // number of batteries in the car }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.