Question: You can define the compareTo method in a class without implementing the Comparable interface. What are the benefits of implementing the Comparable interface? class B

You can define the compareTo method in a class without implementing the Comparable interface. What are the benefits of implementing the Comparable interface?
class B implements A {
void m1(){
System.out.println("m1");
}
}
Suppose A is an interface. Can you create an instance using new A()?
Suppose A is an interface. Can you declare a reference variable x with type A like this?
A x;
Show the error in the following code:
interface A {
void m1();
}
class B implements A {
void m1(){
System.out.println("m1");
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!