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

  1. Define abstract String getType() and concrete method showInfo() in Vehicle abstract class
  2. showInfo() prints Type: <return value of getType()>
  3. Car returns Car from getType()
  4. Bike returns Bike from getType()
  5. In main, store Car, Bike, Car in a Vehicle[] array and call showInfo() 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