PROGRAMMING EXAM
ANSWER ALL QUESTIONS IN THIS SECTION
QUESTION 1
Which of the following is correct?
A) a parent class is a subclass of its child
B) a base class is a child class or derived class
C) a base class is a parent class or super class
D) a child class is a super class of its parent
E) None of these are correct - ANSWERS-C
QUESTION 2
An int array stores the following values: 9, 4, 12, 2, 6, 8,
Which of the following lists of numbers would accurately show the array after the
third pass of
the selection sort algorithm?
END OF
PAGE
1
, COMPUTER LATEST
PROGRAMMING EXAM
A) 9, 4, 12, 2, 6, 8, 18
B) 2, 4, 6, 9, 8, 12, 18
C) 2, 4, 12, 9, 6, 8, 18
D) 2, 4, 6, 9, 12, 8, 18
E) 2, 4, 9, 12, 6, 8, 18 - ANSWERS-D
QUESTION 3
Polymorphism is achieved by
A) overloading
B) overriding
C) embedding
D) abstraction
E) encapsulation - ANSWERS-B
END OF
PAGE
2
, COMPUTER LATEST
PROGRAMMING EXAM
QUESTION 4
Assume that Student, Employee and Retired are all extended classes of Person, and
all
four classes have different implementations of the method getMoney. Consider the
following code
where . . . indicates the required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney();
p = new Student(...);
int m2 = p.getMoney();
if (m2 < 100000) p = new Employee(...);
else if (m1 > 50000) p = new Retired(...);
int m3 = p.getMoney(); // assignment 3
The reference to getMoney() in assignment 3 is to the class
A) Person
B) Student
C) Employee
END OF
PAGE
3
, COMPUTER LATEST
PROGRAMMING EXAM
D) Retired
E) This cannot be determined by
examining the code - ANSWERS-E
QUESTION 6
What class hierarchy involving classes L, M, and N would make the following
code valid?
L l; M m; N n;
l = new M(); l = new N(); m = new N();
A) Classes M and N must both be subclasses of class L.
B) Class M must be a subclass of class N, which is a subclass of class L.
C) Class N must be a subclass of class M, which is a subclass of class L.
D) Classes L must be a subclass of class M and also a subclass of class N.
E) There is no class hierarchy that would allow this code. - ANSWERS-C
END OF
PAGE
4