What should be inserted in the code given below at line marked // 10:
class MyClass{ } class MyComparable implements Comparable<MyClass>{ public int compareTo ( *INSERT CODE HERE* x ){ //10 return 0; } }
Select 1 option
Correct Option is : B
Since MyComparable
class specifies that it implements the Comparable interface that has been typed to MyClass, it must implement compareTo()
method that takes a MyClass.
Had it not declared a typed Comparable in its implements clause, compareTo
(Object x) would have been correct.