About Question enthuware.ocajp.i.v7.2.1390 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Smoljanov Sergej
Posts: 4
Joined: Mon Sep 15, 2014 8:24 am
Contact:

About Question enthuware.ocajp.i.v7.2.1390 :

Post by Smoljanov Sergej »

What can be inserted in the code below so that it will print UP UP UP?

Code: Select all

public class Speak {     
    public static void main(String[] args) {         
        Speak s = new GoodSpeak();          
        INSERT CODE HERE      
    } 
} 
class GoodSpeak extends Speak implements Tone
{     
    public void up(){
        System.out.println("UP UP UP");     
    } 
} 
interface Tone{     
    void up(); 
}
i want know why option
((Tone)s).up();
is not correct?
i assume that this code will have same result as

Code: Select all

Tone tone = ((Tone)s);
tone.up();
and because polymorphism up() will be run from actual object (which is GoodSpeak).
when i try this code i have same result "UP UP UP"
i think in this example was 2 right answer.

admin
Site Admin
Posts: 10389
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1390 :

Post by admin »

You are right. Option 2 is correct as well. Fixed.
thank you for your feedback!
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests