Page 1 of 1

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

Posted: Tue Sep 30, 2014 4:45 am
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.

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

Posted: Tue Sep 30, 2014 9:10 am
by admin
You are right. Option 2 is correct as well. Fixed.
thank you for your feedback!
Paul.