In: Computer Science
4)
Define an abstract class |
Name Java class that implements interface Comparable
|
Hi, I hope you are doing well.
4)
Abstract class: Abstract class is defined with the abstract keyword.
Syntax: abstract class B{}
The abstract class can have both methods abstract as well as non-abstract. An abstract class is needs to be extended and its method needs to be implemented. But it cannot be instantiated. It can have final and static methods also. It can also have constructors too. Final method will force the subclass to not change the body of method. This are the main points to remeber the abstract class.
Comparable interface: The comparable interface is used to order the objects of user defined class(that contains arrays or list ). The comparable interface is found in java.lang package and it only contains one method compareTo(Object).
we can sort the elements of the following type of objects by the comparable insterface: