Intermediate
Rust
Q40 / 100
What is a trait object (dyn Trait)?
Correct! Well done.
Incorrect.
The correct answer is B) A runtime-dispatched reference to any type implementing a trait, enabling dynamic polymorphism via a vtable
B
Correct Answer
A runtime-dispatched reference to any type implementing a trait, enabling dynamic polymorphism via a vtable
Explanation
Box<dyn Animal> or &dyn Animal is a fat pointer (data ptr + vtable ptr) that can hold any Animal implementor. Use when concrete types aren't known at compile time.
Progress
40/100