GATE / CS ARCHIVE

GATE CSE 2004 / QUESTION 34

Employee-class design

Engineering Mathematics & Other Topics · Other Computing Topics · Full GATE CSE 2004 paper

GATE 2004, Q34 2 marks · MCQ
Not in GATE 2027 syllabusReport issue

Other Computing Topics

Question 34, GATE 2004: An employee system has superclass Employee and subclasses Manager, Engineer and Secretary. Each employee has name, unique ID and salary; salary depends on category. Choose the best design for getName, getId and computeSalary (called getSalary in the numbered statements). (i) Implement getId in superclass; (ii) implement getId in subclass; (iii) getName abstract in superclass; (iv) implement getName in superclass; (v) implement getName in subclass; (vi) getSalary abstract in superclass; (vii) implement getSalary in superclass; (viii) implement getSalary in subclass.
Options:
(A) i,iv,vi,viii
(B) i,iv,vii
(C) i,iii,v,vi,viii
(D) ii,v,viii
Question 34, GATE 2004: An employee system has superclass Employee and subclasses Manager, Engineer and Secretary. Each employee has name, unique ID and salary; salary depends on category. Choose the best design for getName, getId and computeSalary (called getSalary in the numbered statements). (i) Implement getId in superclass; (ii) implement getId in subclass; (iii) getName abstract in superclass; (iv) implement getName in superclass; (v) implement getName in subclass; (vi) getSalary abstract in superclass; (vii) implement getSalary in superclass; (viii) implement getSalary in subclass.
Options:
(A) i,iv,vi,viii
(B) i,iv,vii
(C) i,iii,v,vi,viii
(D) ii,v,viii
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. The common name and identifier accessors can be implemented once in Employee, statements i and iv. Salary computation varies by employee category, so declare it abstract in Employee and implement it in each category subclass, vi and viii.

2. Thus A is the best listed design. The narrative says computeSalary while the numbered statements say getSalary; the intended varying salary operation is treated consistently.

3. Teaching check: Inheritance should share the common accessors while polymorphism handles category-specific salary rules. An abstract salary method specifies the common interface without imposing one implementation. Making getName abstract duplicates a behavior that the problem gives no reason to vary.

Original paper, page 4