Software Engineering · Software Engineering and Web Technology
56 questions · asked in 11 of 27 years (2000–2026)
MCQ 53 · NAT 31-mark 42 · 2-mark 14
2000Questions per year2026
Questions 56–56 of 56
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 etermined by their category. The functions get Name, getld and compute salary are required. Given the class hierarchy below,possible locations for these functions are:
(i) getld is implemented in the superclass
(ii) getld is implemented in the subclass
(iii) getName is an abstract function in the superclass
(iv) getName is implemented in the superclass
(v) getName is implemented in the subclass
(vi) getSalary is an abstract function in the superclass
(vii) getSalary is implemented in the superclass
(viii) getSalary is implemented in the subclass
Choose the best design
(i) getld is implemented in the superclass
(ii) getld is implemented in the subclass
(iii) getName is an abstract function in the superclass
(iv) getName is implemented in the superclass
(v) getName is implemented in the subclass
(vi) getSalary is an abstract function in the superclass
(vii) getSalary is implemented in the superclass
(viii) getSalary is implemented in the subclass
Choose the best design
Answer: (A)
Every employee has a name and an id, and these do not depend on the category. So getId (i) and getName (iv) are implemented once in the superclass, and the subclasses inherit them.
Salary depends on the category (Manager, Engineer, Secretary). So getSalary is an abstract function in the superclass (vi), and each subclass implements it (viii).
This gives (i), (iv), (vi), (viii). The other options are worse. (B) implements getSalary in the superclass, which cannot know each category's rule. (C) makes getName abstract and repeats it in every subclass. (D) puts getId and getName in the subclasses, repeating the same code.
Answer: (A)
Salary depends on the category (Manager, Engineer, Secretary). So getSalary is an abstract function in the superclass (vi), and each subclass implements it (viii).
This gives (i), (iv), (vi), (viii). The other options are worse. (B) implements getSalary in the superclass, which cannot know each category's rule. (C) makes getName abstract and repeats it in every subclass. (D) puts getId and getName in the subclasses, repeating the same code.
Answer: (A)
Keep practising
Topics in Software Engineering and Web Technology
Software EngineeringYou are here
Web Technology