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

Chrome OS will soon be able to run Android apps in the background