Given: What is the result?
A.
tolting cantering tolting
B.
an exception is thrown at runtime
C.
cantering cantering cantering
D.
compilation fails
Given: What is the result?
A.
tolting cantering tolting
B.
an exception is thrown at runtime
C.
cantering cantering cantering
D.
compilation fails
Since public modifier is not there with the ride methods in both classes,
D
but nothing about package names
So A, tested with this code:
–first file
public interface Rideable {
String ride();
}
–second file
public class Horse implements Rideable {
@Override
public String ride() {
return “cantering”;
}
}
–third file
public class Icelandic extends Horse {
@Override
public String ride() {
return “tolting”;
}
}
–forth file
public class Test1 {
public static void main(String[] args) {
Rideable r1 = new Icelandic();
Rideable r2 = new Horse();
Horse h1 = new Icelandic();
System.out.println(r1.ride() + ” ” + r2.ride() + ” ” + h1.ride());
}
}
a
D. compilation fails
A. tolting cantering tolting
i am sure a is correct ;
No Yovrer you are wrong. Code will throw compilation error.
Reason : Ride() method of interface is PUBLIC and when we override it in subclass , we cannot reduce its access visibility.So compiler will complain about it.
Why do you say that the ride() methods in the subclasses are not also public, once they have not access modifier defined?
D
D
D