About Question enthuware.ocajp.i.v7.2.1390 :
Posted: Tue Sep 30, 2014 4:45 am
What can be inserted in the code below so that it will print UP UP UP?
i want know why option
((Tone)s).up();
is not correct?
i assume that this code will have same result as 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.
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();
}
((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();
when i try this code i have same result "UP UP UP"
i think in this example was 2 right answer.