File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Associate Certification (OCAJP 7) and the fly likes Multiple casts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "Multiple casts" Watch "Multiple casts" New topic

Multiple casts

George Panadis

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: 3255
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

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: [read Tony Docherty's reply ]

Also look for the reply of Jeff Verdegan on this thread:
He explains the rules of casting in that thread nicely.
I agree. Here's the link:
subject: Multiple casts
Similar Threads
Isn't Implementing Interfaces Inheritence ?
overriding ignores cast ?? Please explain
Valiveru's Mock Exam: Question #7
Multiple Interface Inheritance / Interface Inheritance
Extending interface