| Author |
Multiple casts
|
George Panadis
Greenhorn
Joined: Jun 25, 2012
Posts: 14
|
|
I have been studying for the exam and I started doing some practice tests.
I came across something I haven't seen before (multiple and interface casts) and I am having difficulty finding anything about it online.
Identify options that will compile and run without error.
What are the rules for multiple casts? How do I go about deciphering those?
|
 |
Paul Anilprem
Enthuware Software Support
Ranch Hand
Joined: Sep 23, 2000
Posts: 2912
|
|
Interface cast works exactly the same as a class cast and a multiple cast is not much different from a single one. You should break a multiple into two single casts as shown below:
b = (B)(I) a;
is same as:
I temp = (I) a;
b = (B) temp;
Now, if you know single casts, there should be no issue with the above
|
Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
|
 |
George Panadis
Greenhorn
Joined: Jun 25, 2012
Posts: 14
|
|
okay. thank you for the reply.
I wouldn't say im 100% confrotable with object casting but I understand.
Its one of those things that the longer I look at the less sense it makes so I need to get more confortable with them.
|
 |
Rohan Deshmkh
Ranch Hand
Joined: Aug 31, 2012
Posts: 127
|
|
I had asked the same question some 10-12 days ago, you can have a look at answers here:
http://www.coderanch.com/t/593352/java/java/Confused-ClassCastException
http://www.coderanch.com/t/593431/java/java/output-Casting [read Tony Docherty's reply ]
Also look for the reply of Jeff Verdegan on this thread: http://www.coderanch.com/t/566171/java/java/polymorphism-casting-logic#2572095.
He explains the rules of casting in that thread nicely.
|
 |
 |
|
|
subject: Multiple casts
|
|
|