Page 3 of 3

Re: About Question enthuware.ocajp.i.v7.2.1328 :

Posted: Wed Dec 02, 2020 6:06 am
by Dreamweaver
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


casting3.jpg
casting3.jpg (9.2 KiB) Viewed 2317 times
Is that correct?

Re: About Question enthuware.ocajp.i.v7.2.1328 :

Posted: Wed Dec 02, 2020 6:24 am
by admin
At the end of the statement, a should be pointing to the B object.

Re: About Question enthuware.ocajp.i.v7.2.1328 :

Posted: Wed Dec 02, 2020 6:37 am
by Dreamweaver
Thank you very much, I updated the image:
casting6.jpg
casting6.jpg (10.27 KiB) Viewed 2314 times

Re: About Question enthuware.ocajp.i.v7.2.1328 :

Posted: Wed Dec 02, 2020 6:38 am
by admin
Looks good now :)

Re: About Question enthuware.ocajp.i.v7.2.1328 :

Posted: Wed Oct 06, 2021 5:15 pm
by jpena112
Can you explain more towards this answer

Re: About Question enthuware.ocajp.i.v7.2.1328 :

Posted: Wed Oct 06, 2021 8:47 pm
by admin
Can you please tell us which part do you have a difficulty understanding so that we can explain that?

You may also go through the responses posted above.