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.
The question is wrong – only A is the answer, but asked for “two” correct statements.
c is correct also. notice it overloads
+1
overloads =>void write() {}
c no “{}”
Only A is correct.
B and D must be public at least to be an override or implementation
C might be an overload, but should either be abstract or have an implementation.
E is missing the returntype.
B and C, tested.
B overwrites interface method,
C only adds a new abstract method to the abstract class.
AE are correct.
E no Return type
A,E >> for C compilation fails.
A
E
AE
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 () {}
}