the instanceof operator uses the runtime type of the left operand and compares it with the type on the right operand.
From
JLS 15.20.2 Type Comparison Operator instanceof
At run time, the result of the instanceof operator is true if the value of the RelationalExpression (left operand) is not null and the reference could be cast (�15.16) to the ReferenceType (right operand) without raising a ClassCastException. Otherwise the result is false.
Let's analyze your example:
I x = new D();
The compile-time type of x is I.
The runtime types of x can be D, C, J and I (and Object).
You can cast x to J without getting a ClassCastException since x is actually of type J, and thus, the instanceof statement yields true and "J" is printed.
[ March 21, 2002: Message edited by: Valentin Crettaz ]