Question: Write an application that demonstrates polymorphic features. The application must contain 4 classes (Vehicle, Car, Truck, PolymorphicApp). Car and Truck inherit from Vehicle The Vehicle

Write an application that demonstrates polymorphic features. The application must contain 4 classes ("Vehicle", "Car", "Truck", "PolymorphicApp"). "Car" and "Truck" inherit from "Vehicle" The "Vehicle" class must contain a method called "drive( )" The derived classes must override the "drive( )" method The "Vehicle" class must contain a constructor and a default implementation or the "drive( )" method. The subclasses must contain contructors and an implementation for the "drive( )" methods that override the "Vehicle" class version.

The application class, "PolymorphicApp" must perform the following.

1. Declare an array of three "Vehicle" references

2. Create an instance of each subclass (i.e., object of "Car" and "Truck"). There will be a total of 2 objects

3. Assign each array reference element to one of the objects

4. Create a loop that iterates through the array and invokes the "drive()" method

Note: The idea is that each call to "drive( )" will display a different message based on the type of object that is referenced.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!