How does Run-Time Type Information (RTTI) allow a program to determine an object's actual type at runtime?

Last updated 5 July 2026

  • RTTI (Run-Time Type Information) keeps type metadata attached to objects (e.g. via the vtable in C++ or the class object in Java/C#), revealing the actual dynamic type behind a reference's declared static type.

  • Operators query this metadata: typeid / dynamic_cast (C++), instanceof / getClass() (Java), is / GetType() (C#). Checked casts return null or throw instead of causing undefined behavior.

  • In C++ it requires polymorphic types and adds slight overhead. Heavy type-switching on RTTI is a design smell, so prefer virtual dispatch.

  • https://pvs-studio.com/en/blog/posts/cpp/0998/
  • https://www.geeksforgeeks.org/cpp/rtti-run-time-type-information-in-cpp/
All Object-Oriented Programming interview questions