INTERVIEW QUESTION(JAVA)

VERY IMPORTANT INTERVIEW QUESTION(JAVA)
Why CompareTo() has one parameter and Compare() has two parameters?
Ans= ComapreTo() method will be implemented in the same adding object class. So among two objects one object is send as current object, another object is sent as argument object. Hence CompareTo() method has only one parameter.

Compare() method will be implemented in the other class, not in adding object class. So the two object must be passed as argument. Hence compare() method has two parameters.

Comments

Popular posts from this blog

Apple apologises to users over slowing down older iPhones; slashes battery replacement costs by $50

Digital, People and Data are likely to dominate in 2018: Virtusa CIO Madu Ratnayake