File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question Mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question Mock" Watch "Question Mock" New topic
Author

Question Mock

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!

public class Test011 extends Object
{
public static void main(String args[])
{
Test011 t = new Test011();
System.out.print(null.equals(t)); //1
System.out.print(" ");
System.out.println(t.equals(null)); //2
}
}
The answer is:
B: The code compiles but at runtime throws
NullPointerException at line //1.
But I can not compile this code, the compiler throw Error(13) null cannot be dereferenced.
Whats happend??
Thank you in advance
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Compiler complains because null is not an object. It cannot receive any message (method). Try 5.equals();
null is a literal for assigning a (null) value to any reference variable.
by the way are you Spanish?


SCJP2. Please Indent your code using UBB Code
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
yes I�m Spanish, are you Spanish also?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Yes I am please see my Java pages at http://usuarios.tripod.es/JoseBotella
I will be adding a new article about Collections in a while
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I saw your page web and sent you a mail but I don�t had response.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question Mock