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. Read employee information from standard input, store them 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 - Read employee data from standard input and build an Employee array
- For each employee, output "Manager: [name], Team: [size]" if Manager, "Developer: [name], Language: [language]" if Developer
Input Format
N
[type1] [name1] [extra1]
[type2] [name2] [extra2]
...
- Line 1: Number of employees N (1 ≤ N ≤ 10)
- Next N lines: Employee information
- For Manager:
Manager [name] [teamSize (integer)] - For Developer:
Developer [name] [language]
- For Manager:
Output Format
Output each employee's information in input order.
Manager: [name], Team: [teamSize]
Developer: [name], Language: [language]
Sample Input
2
Manager Alice 5
Developer Bob Java
Sample Output
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