downcasting
Downcasting is the explicit conversion of a reference or pointer from a base class to a derived class type. It is often necessary when code stores objects in a collection of base type but later needs access to derived-specific members. Downcasting is contrasted with upcasting, which safely converts a derived object to its base type and is usually implicit.
In languages with runtime type information, downcasting can be checked at runtime. Java requires a cast and
Slicing risk: in languages like C++, downcasting by value can cause object slicing; storing a derived object
Best practices: minimize downcasting; prefer virtual dispatch and polymorphism; use type checks when necessary; encapsulate type-specific