Question: QUESTION 8 (a) Why would a class implement the Comparable interface? What is the method of the Comparable interface? (4 marks) (b) Given below is
QUESTION 8 (a) Why would a class implement the Comparable interface? What is the method of the Comparable interface? (4 marks) (b) Given below is a class Car that has attributes Make and regNum. Your task is to rewrite the code so that it implements the Comparable interface. The ordering is based on regNum only. public class Car \{ private String make, regNum; public Car(String m, String n ) \{ make =m; regNum =n; \} public String makeO \{ return make; \} public String regNum0 0 return regNum; \} public void setMake(String m) make=m; \} public void setRegNum(String n ) \{ \} regNum=n; public String toString 0 \{ return make +" - "+ regNum; \} \}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
