Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

b. Wh at\'s wrong with the following code for interface? What should be changed

ID: 3728585 • Letter: B

Question

b. Wh at's wrong with the following code for interface? What should be changed to make a valid interface for objects that have colors? public interface Colored private Color color; public Color getColor)f return color; Consider the following classes: public class Vehicle public class Car extends Vehicle implements Speed ...) public class sUv extends Car (... c. ..)h Which of the following are legal statements? i. Vehicle v = new Car(); ii. Vehicle vnew SUV) iii. Car c = new SUV ( ); iv. SUV s = new SUV(); v. SUV s = new Car(); vi. car c = new vehicle(); vii. Speed s-new Car (O viii. Speed s = new SUV ( );

Explanation / Answer

b) The body of an interface cannot contain variable declarations and/or method definitions. It can only contain the prototype of the method which will be implemented by the class implementing the interface.

To make it a valid interface we should remove the reference variable (line number 2) and the return statement(line number 4)

public interface Colored {

public Color getColor() {

}

}

c)

i)legal

ii)legal

iii)legal

iv)legal

v)illegal

vi)illegal

vii)legal

viii)legal