016-001-009

Adding Common Logic to Abstract Classes

Medium

Problem Description

Adding Common Logic to Abstract Classes

In this problem, you will create a program that defines common fields and a concrete method in abstract class Employee, implements individual work() methods in subclasses Engineer and Designer using the template method pattern, and displays the results to standard output.

Learning Objective: Understand adding concrete methods and fields to abstract classes (template method pattern)

Overview

Define common fields, concrete methods, and abstract methods in abstract class Employee, implementing individual logic in subclasses.

Specifications

  1. abstract class Employee with String name field and constructor
  2. Concrete method greet(): prints Hello, I am <name>.
  3. Abstract method work(): implemented by subclasses
  4. Engineer extends Employee, work() prints <name> writes code.
  5. Designer extends Employee, work() prints <name> creates designs.
  6. In main, create objects and call greet() and work()

Output Format

Hello, I am Alice.
Alice writes code.
Hello, I am Bob.
Bob creates designs.

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