A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Arduino in Action
this week in the
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
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.
I agree. Here's the link:
subject: UpCasting DownCasting
downcasting or upcasting of ref variable
widening and casting
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013