Sunday 17 March 2013

SCJP - 19 -Given Example



Which, inserted at line 5, will compile? (Choose all that apply.)
A. Programmer debug() { return this; }
B. SCJP debug() { return this; }
C. Object debug() { return this; }
D. int debug() { return 1; }
E. int debug(int x) { return 1; }
F. Object debug(int x) { return this; }

Answer:

A, B, E, and F are correct. A and B are examples of overriding, specifically, B is an
example of overriding using a covariant return. E and F are examples of overloading.

C and D are incorrect. They are illegal overrides because their return types are
incompatible. They are illegal overloads because their arguments did not change.
(Objective 5.4)
==
class Programmer {
Programmer debug() { return this; }
}
class SCJP extends Programmer {
// insert code here
}



No comments:

Post a Comment