overriding equals method in java -
overriding equals method in java -
this question has reply here:
when need override equals , hashcode methods? [duplicate] 3 answersimport java.util.*; public class vehicle implements comparable<vehicle>{ private string name; private int modelno; public vehicle(string name,int modelno ){ this.name=name; this.modelno=modelno; } public void setname(){ this.name=name; } public string getname(){ homecoming name; } public void setmodelno(){ this.modelno=modelno; } public int getmodelno(){ homecoming modelno; } public int compareto(vehicle v){ homecoming v.name.compareto(name); } public int hashcode(){ homecoming 1; } public boolean equals(object o){ } public string tostring(){ homecoming name+" "+modelno; }
i don't know how override equals ? benefit of , why necessary utilize treeset sort object in main class.
for sorting need implement compareto method.
how implement java comparable interface?
java equals hashcode overriding comparable
Comments
Post a Comment