Re: 初级问题# Java - 爪哇娇娃
w*r
1 楼
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.
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.