Hey Ryan,
you're the man!
finally i've got it too. These things were the most misconceived topics for me.
The last example of code made it all clear.
I've got to burn this in:
When there are methods on the game i've got to look at the object type.
When there are instance variables i must look at the reference type.
But just to clear this out, once and for all:
what happens in line 11?
object reference x references an Object of type B (which extends A).
with the assignment above i'm doing just a copy of reference x to reference y - right? That means im not changing the objects type, right? Im just saying: y is a reference of type A and and on the heap, there is an object of type B, referenced by x.
So when i'm doing polymorphism like here
the foo method of class B is invoked, because the Object is of type B.
I am asking because i'm wondering about this
I always pretended that (through
(A)x ) the object referenced by y is from now on of type A, but it's just a upcast - is'nt it?