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
abstract class EmployeewithString namefield and constructor- Concrete method
greet(): printsHello, I am <name>. - Abstract method
work(): implemented by subclasses Engineerextends Employee, work() prints<name> writes code.Designerextends Employee, work() prints<name> creates designs.- 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