Outcast Downcasting

suggest change

Beware of using “downcasting” - Downcasting is casting down the inheritance hierarchy from a base class to a subclass (i.e. opposite of polymorphism). In general, use polymorphism & overriding instead of instanceof & downcasting.

C++ Example

// explicit type case required
Child *pChild =  (Child *) &parent;

Java Example

if(mySubClass instanceof SubClass) {
   SubClass mySubClass = (SubClass)someBaseClass;

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents