Difference between Comparable and Comparator in JAVA using an example

preview_player
Показать описание
In this video you will learn what's the difference between Comparable and Comparator
in JAVA using an example
Below is the GitHub link to download source:
Рекомендации по теме
Комментарии
Автор

You explained it really well!! Thank you :)

khushboopandey
Автор

Great video, but I might summarize differently. If there is just one obvious way to be sorting your objects, then Comparable is your best choice. If there is more than one equally good way that someone might want to see them sorted, then better to go for Comparator. Now, if your object only has one data member, then usually Comparable makes sense, and if your object has a lot of data members, than usually Comparator makes more sense. But the question really is "How likely is someone to want a sort order different than this one?" Very Unlikely: Comparable. Pretty Likely: Comparator.

jvsnyc
Автор

class A{
public A(){Systen.out.println("A constructor is call")}
class B extends A{
public B(){Systen.out.println("B constructor is call")}
class Test{
public static void main(String [] args){
A a1=new B();
}
}
what is the out of this program

Arjunkumar-cxpg