File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Joined: Aug 11, 2006
Feb 06, 2007 21:01:00
Upcasting DownCasting example please.
Enthuware Software Support
Joined: Sep 23, 2000
Feb 06, 2007 21:43:00
Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Joined: Feb 06, 2007
Feb 08, 2007 12:08:00
a = new
Collection c = a; // upcast implicit no need for (
b = (
)c; // downcast requires explicit cast
upcast dont require an explicit cast as a subclass is always guaranteed to pass the is-a
with its parent. ie
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.
Don't get me started about those stupid
subject: UpCasting DownCasting
widening and casting
downcasting or upcasting of ref variable
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014