jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enum Doubt 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 "Enum Doubt" Watch "Enum Doubt" New topic
Author

Enum Doubt

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509


here the answer is null, why isnt there a Null Pointer Exception.? :?:
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Why it should throw nullpointerexception ?


SCJP 6
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
wont it call the toString() method, which enums override from the Object class?
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Days d is just a reference where is object assigned to it ? It has been assigned null, and for null JVM always prints null as output.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
As often is the case, the JVM has the answer.

If you look up the PrintStream (System.out is a PrintStream object) println(Object) method, you'll see that it calls print(String.valueOf(Object)) then println().
In the String API, String.valueOf(Object) then states "if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned."
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
pete stein wrote:As often is the case, the JVM has the answer.

If you look up the PrintStream (System.out is a PrintStream object) println(Object) method, you'll see that it calls print(String.valueOf(Object)) then println().
In the String API, String.valueOf(Object) then states "if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned."


You are talking about this na.


Really nice info Pete

 
 
subject: Enum Doubt