Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training

Here class A and B is-NOT-a I

then why A[] is casted to I[]

The rule of thumb about interfaces is, at the compile time, you can cast between any non-final class and an interface, even if there was not an is-a relationship.


Here's an example:


interface I { }
class B { }

I obj = (I) new B();


The above line compiles. It however fails at the run time with a ClassCastException due to the fact that B is-not-a(n) I.


ExamLab © 2008 - 2024