Leave a Reply 10

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


stack

stack

Since public modifier is not there with the ride methods in both classes,

D

duff

duff

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());
}

}

Sanjukta

Sanjukta

D. compilation fails

yovrer

yovrer

A. tolting cantering tolting
i am sure a is correct ;

ARJIT GAUTAM

ARJIT GAUTAM

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.

Hugo

Hugo

Why do you say that the ride() methods in the subclasses are not also public, once they have not access modifier defined?