SCJP Java Script
Saturday, 16 March 2013
SCJP - 1 - Which code fragments will compile?
1. Given the following,
1. interface Base {
2. boolean m1 ();
3. byte m2(short s);
4. }
Which code fragments will compile? (Choose all that apply.)
A. interface Base2 implements Base { }
B. abstract class Class2 extends Base {
public boolean m1() { return true; } }
C. abstract class Class2 implements Base { }
D. abstract class Class2 implements Base {
public boolean m1() { return (true); } }
E. class Class2 implements Base {
boolean m1() { return false; }
byte m2(short s) { return 42; } }
Answer:
C and D are correct. C is correct because an abstract class doesn't have to implement any
or all of its interface's methods. D is correct because the method is correctly implemented.
A is incorrect because interfaces don't implement anything. B is incorrect because classes
don't extend interfaces. E is incorrect because interface methods are implicitly public, so
the methods being implemented must be public. (Objective 1.1)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment