由买买提看人间百态

topics

全部话题 - 话题: varparent
(共0页)
w****r
发帖数: 2
1
来自主题: Java版 - Re: 初级问题
Object is the base class in Java, each class in Java will inherit
Object even if you don't use 'extends Object', it's to say:
class A {...}
equals
class A extends Object{...}
you can get the assignment as you want,
class A {...}
class ChildClass extends A {...}
...
A varParent = ...;
ChildClass varChild = (ChildClass) varParent;
But pls note: the runtime type of varParent must be
ChildClass or ChildClass' subclass. otherwise you will
get runtime assignment exception.
(共0页)