Here it gives compiler error.I thought it would print "We are not Equal". Cant we use null with equals method??
Rushikesh Wagh
Ranch Hand
Joined: Jun 18, 2005
Posts: 58
posted
0
.equals() Method Is Used To Compare The Objects And null Is Not An Object. Hence It Has Compile Time Error. Please Do Correct Me If I m Wrong.
Best Regards,
Rushikesh Wagh
SCJP 1.4 (2005)
SCJP 1.6 (2010)
Ryan Kade
Ranch Hand
Joined: Aug 16, 2005
Posts: 69
posted
0
Rushikesh is correct, null is a literal, not an object. Trying to call a method on null would be like trying to call a method on the number 5 or the boolean value true.