Question: (a) (b) Why would a class implement the Comparable interface? What is the method of the Comparable interface? (4 marks) Given below is a

(a) (b) Why would a class implement the Comparable interface? What is the method of the Comparable interface? 

(a) (b) Why would a class implement the Comparable interface? What is the method of the Comparable interface? (4 marks) 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 make() { return make; } public String regNum() { return regNum; } public void setMake(String m) { make=m; } public void setRegNum(String n) { regNum=n; } public String toString() { return make +""+regNum; (6 marke)

Step by Step Solution

3.40 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a A class implements the Comparable interface to allow objects of that class to be compared to each ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!