Given:
1. interface Writable {
2. void write (String s);
3. }
4 .
5. abstract class Writer implements Writable {
6. // Line ***
7. }
Which two statements are true about the writer class?
A.
It compiles without any changes.
B.
It compiles if the code void write (String s); is added at line***.
C.
It compiles if the code void write (); is added at line ***.
D.
It compiles if the code void write (string s) { } is added at line ***.
E.
It compiles if the code write () {}is added at line ***.
Explanation:
An abstract class does not need to implement the interface methods.
Which two statements?.. A is fine, and other I think has to be B, but as ‘public void write (String s);
Correct answers are A, E.
B incorrect because:
assigning weaker access modifier (package access) was public
C incorrect because:
the method must be marked abstract if withoud body
D incorrect because:
same reason as per B answer. Even we are providing implementation the access modifier is restricted to package-local rather than public
A,D
D tested fine
May I know how you exactly tested it? D?
A is the only correct answer. You must not implement the interface in a abstract class, but in the first concrete class.
you are not right
you can implement interface class in abstract class
Correct answers are A, E.
Correct answers are A, E.
E is incorrect, missing void prior to write(){}
A D
AE as Francesco analyzed.
Only A is correct.
D is incorrect : reduce the visibility of the inherited method from Writable (should be public method in Writer class)
E is incorrect : write () {} missing return type
write () {} no need return because void method
answer A,D!
Only A is correct
Yes, after whole set of test codes, only A can be compiled successfully.
just A
A
interface Writable {
void write (String s);
}
abstract class Writer implements Writable {
// Line ***
// A True
// B False
// Cannot reduce the visibility of the inherited method from Writable
// This method requires a body instead of a semicolon
// void write (String s);
// C False
// This method requires a body instead of a semicolon
// void write ();
// D False
// Cannot reduce the visibility of the inherited method from Writable
// void write (String s) { }
// E False
// Return type for the method is missing
// write () {}
}
ae
a