I'm reviewing for my mid term which I will be taking this evening. On the practice exam, the following question is given:
Given the following, which line is illegal, assuming that class Watch extends class Clock?
Clock A = new Clock();
Watch B = new Watch();
A=B;
B=A;
On the answer key, he states that B=A; is the illegal statement because a Clock is not necessarily a Watch...but that feels wrong. I feel that in this, A=B; would be the illegal statement. But I also understand that maybe I don't fully understand how an assignment operator would work in this case. Could someone please explain this to me?
Given the following, which line is illegal, assuming that class Watch extends class Clock?
Clock A = new Clock();
Watch B = new Watch();
A=B;
B=A;
On the answer key, he states that B=A; is the illegal statement because a Clock is not necessarily a Watch...but that feels wrong. I feel that in this, A=B; would be the illegal statement. But I also understand that maybe I don't fully understand how an assignment operator would work in this case. Could someone please explain this to me?
Comment