The reason why you get 5 is that you are looking at the CT class, not the SCT. The SCT-class knows about the 6, the CT does not.
You can look at the superclass A as a big box that exposes its methods and attributes on the outside of the box.
The sub class B also exposes its methods and attributes on the outside of its box but since it is "inside" the A-box, you can't see the methods and attributes of the B box. [ December 05, 2008: Message edited by: Ove Lindstr�m ]
There are two issues. 1) the getObject() method is going to have return type issues and 2) class CT and class SCT know nothing about classes A and B and their instance variable x. That's what I can make of what you have written.
Software development is an exercise in thinking not coding.
In this case, 5 is returned because you are creating an SC reference. The variable returned depends on the type of the reference. To get 6, use SCT as the reference type. The fact that you are creating an SCT object makes no difference when accessing variables.
Note that this behavior is unlike the one observed when accessing an overridden method, where the type of instance created will be taken into account.