I would like to make copy of SubClass object in BaseClass constructor. I need that the following code execute correctly.
class BaseClass{
BaseClass() {}
It seems like you want the object of BaseClass
to be an instance of SubClass
which extends BaseClass
.
Is it even possible?
-No. It is not possible.
The instanceof
operator returns true
if the variable on left side satisfies IS-A condition of the variable or class on the left side.
The SubClass
IS-A BaseClass
since it extends BaseClass
. But the BaseClass
can never be a SubClass
, since it can't extend SubClass
.