Which statement is true?

Given:

class Car implements TurboVehicle, Steerable {

// Car methods > interface Convertible

{

// Convertible methods

}

public class SportsCar extends Car implements Convertible {

}

Which statement is true?

Given:

class Car implements TurboVehicle, Steerable {

// Car methods > interface Convertible

{

// Convertible methods

}

public class SportsCar extends Car implements Convertible {

}

Which statement is true?

A.
SportsCar must implement methods from TurboVehicle and steerable

B.
SportsCar must override methods defined by car.

C.
SportsCar must implement methods define by convertible.

D.
Instances of car can invoke convertible methods.

Explanation:
To declare a class that implements an interface, you include an implements clause in the class declaration.
By convention, theimplements clause follows the extends clause, if there is one.

Here are the some point that must be considered while implementing an interface (or interfaces) into a java class.

A class implementing an interface must either implement all the methods of that interface otherwise known as the abstract class.
A class in java may extend at most one superclass because java does not allow multiple inheritance, by it may implement more than one interface. Multiple inheritance in java is achieved through the interfaces. When a class implements more than one interface then implement statement requires a comma- separated list of interfaces to be implement by that class.



Leave a Reply 4

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


Tim

Tim

I don’t really understand this question – could some body help to explain it?

However, if all comments are ignored, then the answer would be C.

Sudeep

Sudeep

Answer should be D
class Car{
public void f(){}
public void ff() {}
}
interface Convertible{
void f();
}
public class SportsCar extends Car implements Convertible{
public static void main(String[] args) {
SportsCar o = new SportsCar();
o.f();
}
}

We don’t have to implement the methods declared in interface Convertible if the method is already defined in Car.

Mario

Mario

C since SportsCar directly implements Convertible and it is not abstract class.
Therefore it must implement Convertible methods.