H
hon123456
Dear all,
I am trying to learn Java. I found the explanation of
ClassCastException in Sun website as follows. But it seems rather
simple. I don't understand " cast an object to a subclass of which it
is not an instance" in the explanation. Please help me. By the way,
please suggest any good website that explains the ClassCastException in
detail.
Thrown to indicate that the code has attempted to cast an object to a
subclass of which it is not an instance. For example, the following
code generates a ClassCastException:
Object x = new Integer(0);
System.out.println((String)x);
Thanks.
I am trying to learn Java. I found the explanation of
ClassCastException in Sun website as follows. But it seems rather
simple. I don't understand " cast an object to a subclass of which it
is not an instance" in the explanation. Please help me. By the way,
please suggest any good website that explains the ClassCastException in
detail.
From sun:
Thrown to indicate that the code has attempted to cast an object to a
subclass of which it is not an instance. For example, the following
code generates a ClassCastException:
Object x = new Integer(0);
System.out.println((String)x);
Thanks.