Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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? (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
Step: 1
a A class implements the Comparable interface to allow objects of that class to be compared to each ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started