015-005-005

Polymorphism: Dynamic Type Checking

Medium

Problem Description

polymorphism: Dynamic Type Checking

In this problem, you will create a program that uses the instanceof operator to determine the actual type (Manager or Developer) of each object in an Employee array and displays type-specific information to standard output.

Learning Objective: Understand how to determine actual object type at runtime using instanceof operator

Overview

You have Manager and Developer classes that inherit from Employee class. Store different employees in an Employee array and execute different processing based on actual type.

Specifications

  • Employee class: getName() method (returns name), constructor receives name
  • Manager class: Inherits Employee, getTeamSize() method (returns team size), constructor receives name and team size
  • Developer class: Inherits Employee, getLanguage() method (returns language), constructor receives name and language
  • Store Manager("Alice", 5) and Developer("Bob", "Java") in Employee array
  • For each employee, output "Manager: [name], Team: [size]" if Manager, "Developer: [name], Language: [language]" if Developer

Output Format

Manager: Alice, Team: 5
Developer: Bob, Language: Java

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