edited by
22,004 views
14 votes
14 votes

It is desired to design an object-oriented employee record system for a company. Each employee has a name, unique id, and salary. Employees belong to different categories and their salary is determined by their category. The functions get name, getId and compute salary are required. Given the class hierarchy below, possible locations for these functions are:

  1. getId is implemented in the superclass

  2. getId is implemented in the subclass

  3. getName is an abstract function in the superclass

  4. getName is implemented in superclass

  5. getName is implemented in subclass

  6. getSalary is an abstract function in the superclass

  7. getSalary is implemented in the superclass

  8. getSalary is implemented in the subclass

Choose the best design

  1. I, IV, VI, VIII
  2. I, IV, VII
  3. I, III, V, VI, VIII
  4. II, V, VIII
edited by

3 Answers

Best answer
34 votes
34 votes
A.

Name and id are a property of every employee and independent of their category. So, these should be implemented in superclass. Every employee has a salary but this is determined by their category. So, getSalary must be a abstract function in superclass and implemented in subclass.
selected by
4 votes
4 votes
Getid() and GetName() can be there in the super class as these functions have the same implementation for all subclasses. As the question says that every employee must have salary and salary is determined by their category, getSalary() must be there as an abstract function in super class. And all subclasses should implement salary according to their category.
–1 votes
–1 votes
Ans is C

GetId is unique so it will represent in  superclass

Get name and salary are not unique do they will be represented in subclass and abstract from the superclass
Answer:

Related questions

59 votes
59 votes
4 answers
3
go_editor asked Apr 24, 2016
19,515 views
Consider the following program segment for a hypothetical CPU having three user registers $R_1, R_2$ and $R_3.$\begin{array}{|l|l|c|} \hline \text {Instruction} & \text...