long is a primitive and not an Object. equals() is a method and it can be called only on a method.
For comparing the equality of primitives, we always use '=='.
If you want, you can try equals() method after wrapping it with java.lang.Long wrapper class.
Vinoth Kumar Kannan wrote:equals() is a method and it can be called only on a method.
Huh? Methods do not have methods (in Java). Did you mean something else?
Oops a typing err...equals() is a method and it can be called only on a Object! Sorry about that! I had something in mind, and typed something else! I'm right now laughing at myself for doing that - calling a method on a method! lol
Gotta get some real sleep, I guess!
You may also find a question in the exam that try to use equals() method to compare or compareTo() method to sort applied on primitives.
Be sneaky in the code and run towards the option thats says compilation failure