File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Downcasting 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 "Downcasting" Watch "Downcasting" New topic


Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 423

I have given the question in the comments..Please advice.

OCPJP 6.0-81% | Preparing for OCWCD | |
Ankit Garg

Joined: Aug 03, 2008
Posts: 9463

Yes null value is downcasted to type Hyderabad and then automatically upcasted to AP. null value can be type casted to any type which is not a primitive...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rahul Saple
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
Yes, we are explictly downcasting the reference (Universe) to Hyderabad and the compiler does the implicit Upcasting (since it is always error free) for us. Assigning a null value is never a problem. Only using(calling a method, accessing a field) a reference pointing to no object in particular(null) leads to an exception. Infact, a non-local reference variable when declared has its default value set to null.
I agree. Here's the link:
subject: Downcasting
It's not a secret anymore!