Which two statements are true about the writer class?

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?

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.



Leave a Reply 19

Your email address will not be published. Required fields are marked *


Boris

Boris

Which two statements?.. A is fine, and other I think has to be B, but as ‘public void write (String s);

Francesco

Francesco

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

Elaine

Elaine

A,D
D tested fine

Rad

Rad

May I know how you exactly tested it? D?

ses

ses

A is the only correct answer. You must not implement the interface in a abstract class, but in the first concrete class.

wojtek

wojtek

you are not right
you can implement interface class in abstract class

Robertinho

Robertinho

Correct answers are A, E.

Ray

Ray

Correct answers are A, E.

Elaine

Elaine

E is incorrect, missing void prior to write(){}

Charlie

Charlie

AE as Francesco analyzed.

hafid

hafid

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

hieu

hieu

write () {} no need return because void method
answer A,D!

Eloi

Eloi

Only A is correct

Tim

Tim

Yes, after whole set of test codes, only A can be compiled successfully.

gelete

gelete

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 () {}
}