Outcast Downcasting

suggest change

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

C++ Example

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

Java Example

if (someBaseClass instanceof SubClass) {
   SubClass mySubClass = (SubClass) someBaseClass;
   mySubClass.nonInheritedMethod();
}

Feedback about page:

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



Table Of Contents