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?
About Question enthuware.ocajp.i.v7.2.1328 :
Moderator: admin
-
- Posts: 32
- Joined: Mon Dec 29, 2014 4:14 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1328 :
At the end of the statement, a should be pointing to the B object.
-
- Posts: 32
- Joined: Mon Dec 29, 2014 4:14 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1328 :
Thank you very much, I updated the image:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1328 :
Looks good now 

-
- Posts: 1
- Joined: Wed Oct 06, 2021 1:32 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1328 :
Can you explain more towards this answer
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1328 :
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.
You may also go through the responses posted above.
Who is online
Users browsing this forum: No registered users and 5 guests