I have a question to reference variables. My question is whether the type of a declared variable refers to the type of the Object or to the type of the reference which is stored in it?
I found a very interesting answer of Edwin Dalorzo on this topic. He describes that every reference has a type and when we perform a typecast it does only change the type of the reference used to refer to that object (not the type of that object itself!).
So my question is whether the type of a reference variable tells us which type of reference is stored in it. Of course the type of the Object and the type of the reference are the same.
Suppose B a = new B();
Does B now tell the compiler that a holds references of type B?
Or does the compiler completely ignore the type of the data that is stored in it (the reference) and only thinks of the type of the underlying object? Same for method return type.