Which three lines will compile and output “right on!”?

Given:
<code>
public class Speak { /* Line 1 */
public static void main(String[] args) { /* Line 2 */
Speak speakIT = new Tell(); /* Line 3 */
Tell tellIt = new Tell(); /* Line 4 */
speakIT.tellItLikeItIs(); /* Line 5 */
(Truth)speakIt.tellItLikeItIs(); /* Line 6 */
((Truth)speakIt).tellItLikeItIs(); /* Line 7 */
tellIt.tellItLikeItIs(); /* Line 8 */
(Truth)tellIt.tellItLikeItIs(); /* Line 9 */
((Truth)tellIt).tellItLikeItIs(); /* Line 10 */
}
}
class Tell extends Speak implements Truth {
public void tellItLikeItIs() {
System.out.println(“Right on!”);
}
}
interface Truth { public void tellItLikeItIs()};
</code>
Which three lines will compile and output “right on!”?

Given:

public class Speak { /* Line 1 */
public static void main(String[] args) { /* Line 2 */
Speak speakIT = new Tell(); /* Line 3 */
Tell tellIt = new Tell(); /* Line 4 */
speakIT.tellItLikeItIs(); /* Line 5 */
(Truth)speakIt.tellItLikeItIs(); /* Line 6 */
((Truth)speakIt).tellItLikeItIs(); /* Line 7 */
tellIt.tellItLikeItIs(); /* Line 8 */
(Truth)tellIt.tellItLikeItIs(); /* Line 9 */
((Truth)tellIt).tellItLikeItIs(); /* Line 10 */
}
}
class Tell extends Speak implements Truth {
public void tellItLikeItIs() {
System.out.println("Right on!");
}
}
interface Truth { public void tellItLikeItIs()};

Which three lines will compile and output “right on!”?

A.
Line 5

B.
Line 6

C.
Line 7

D.
Line 8

E.
Line 9

F.
Line 10



Leave a Reply 6

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


Marin R

Marin R

C, D and F is correct. Line 5 will not compile

Kalil Peixoto

Kalil Peixoto

C,D and F are correct.

sully

sully

why does line 5 not compile?

Oene Bakker

Oene Bakker

I agree C D F are the correct answers

Line 5 will give you an method is undefined for type error.
Line 6 and 9 have the wrong syntax, should be ( (class) var ).method( )