Bird
0
0

You want to design a system where different types of employees calculate their salary differently. Which approach best uses abstract and concrete classes?

hard📝 Application Q15 of 15
Java - Abstraction
You want to design a system where different types of employees calculate their salary differently. Which approach best uses abstract and concrete classes?
ACreate only concrete classes for each employee type without any abstract class.
BCreate an abstract class Employee with an abstract method calculateSalary(), then create concrete subclasses like Manager and Developer implementing it.
CUse an interface with no methods and concrete classes implementing it.
DCreate a concrete Employee class with a fixed calculateSalary() method used by all employees.
Step-by-Step Solution
Solution:
  1. Step 1: Identify need for shared rules with different implementations

    Employee types share concept of salary calculation but differ in details.
  2. Step 2: Use abstract class with abstract method

    Abstract class Employee defines calculateSalary() abstractly. Subclasses implement specific logic.
  3. Step 3: Evaluate other options

    Create only concrete classes for each employee type without any abstract class. lacks shared abstraction. Use an interface with no methods and concrete classes implementing it. uses interface with no methods, so no contract. Create a concrete Employee class with a fixed calculateSalary() method used by all employees. fixes salary calculation, no variation.
  4. Final Answer:

    Create an abstract class Employee with an abstract method calculateSalary(), then create concrete subclasses like Manager and Developer implementing it. -> Option B
  5. Quick Check:

    Abstract class sets rules, subclasses do work [OK]
Quick Trick: Abstract class for rules, concrete classes for details [OK]
Common Mistakes:
  • Not using abstraction for shared behavior
  • Using concrete class with fixed method only
  • Interfaces without methods don't enforce contracts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes