aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes UpCasting DownCasting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "UpCasting DownCasting" Watch "UpCasting DownCasting" New topic
Author

UpCasting DownCasting

Thirukumaran Gopalakrishnan
Greenhorn

Joined: Aug 11, 2006
Posts: 2
Upcasting DownCasting example please.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3313
    
    7
http://www.codeguru.com/java/tij/tij0070.shtml


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Louis Moloney
Ranch Hand

Joined: Feb 06, 2007
Posts: 59
example:

ArrayList a = new ArrayList();

Collection c = a; // upcast implicit no need for (ArrayList)a

ArrayList b = (ArrayList)c; // downcast requires explicit cast

upcast dont require an explicit cast as a subclass is always guaranteed to pass the is-a test with its parent. ie ArrayList is a Collection.

downcast requires an explicit cast because the object being cast might not be what its being cast to. You are basically saying to the compiler trust me i know what im doing.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UpCasting DownCasting