What is the result?

Given:

interface Rideable {

public String ride() { return “riding “; }

}

class Horse implements Rideable {

public String ride() { return “cantering “; }

}

class Icelandic extends Horse implements Rideable {

public String ride() { return “tolting “; }

}

class Test {

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

}

}

What is the result?

Given:

interface Rideable {

public String ride() { return “riding “; }

}

class Horse implements Rideable {

public String ride() { return “cantering “; }

}

class Icelandic extends Horse implements Rideable {

public String ride() { return “tolting “; }

}

class Test {

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

}

}

What is the result?

A.
riding riding tolting

B.
riding riding cantering

C.
tolting cantering tolting

D.
tolting cantering cantering

E.
Compilation fails.

F.
An exception is thrown at runtime.

Explanation:
The compilation fails at:
interface Rideable {
public String ride() { return “riding “;}
}

Error due to: interface methods cannot have body.



Leave a Reply 2

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


Jav

Jav

E Interfaces can’t have concrete methods