016-003-008
Polymorphism with Abstract Class Array
Medium
Problem Description
polymorphism with abstract class array
In this problem, you will create a program that stores Car and Bike subclass objects in a Vehicle[] abstract class array and calls showInfo() on each object in a loop, demonstrating polymorphism and displaying the result to standard output.
Learning Objective: Store different subclass objects in an abstract class array and process them uniformly in a loop
Overview
Store Car and Bike objects in a Vehicle abstract class array and output all vehicle information using a loop.
Specifications
- Define
abstract String getType()and concrete methodshowInfo()inVehicleabstract class showInfo()printsType: <return value of getType()>CarreturnsCarfromgetType()BikereturnsBikefromgetType()- In main, store Car, Bike, Car in a
Vehicle[]array and callshowInfo()in a loop
Output Format
Type: Car
Type: Bike
Type: Car
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up