Re: About Question enthuware.ocajp.i.v7.2.1328 :
Posted: Wed Dec 02, 2020 6:06 am
I dissected the situation a bit to better understand and I came to the next summary:
interface I { }
class A implements I { }
class B extends A { }
class C extends B { }
public class CastTwice {
public static void main(String[] args) {
A a = new A();
B b = new B();
//a = (B)(I)b; is the same with:
I x = (I) b; // x is type I and is pointing to a B object //Possible because B is-a I
a = (B) x; // x is-a B and so, x is-a a //Possible because B is-a A
Is that correct?
interface I { }
class A implements I { }
class B extends A { }
class C extends B { }
public class CastTwice {
public static void main(String[] args) {
A a = new A();
B b = new B();
//a = (B)(I)b; is the same with:
I x = (I) b; // x is type I and is pointing to a B object //Possible because B is-a I
a = (B) x; // x is-a B and so, x is-a a //Possible because B is-a A
Is that correct?