Recall & Review
beginner
What is runtime polymorphism in C#?
Runtime polymorphism means that the method to be called is determined during program execution, not at compile time. It allows a base class reference to call derived class methods using method overriding.Click to reveal answer
beginner
How do you enable runtime polymorphism in C#?
By declaring a method in the base class as <code>virtual</code> and overriding it in the derived class using <code>override</code>. Then, calling the method through a base class reference triggers the derived class version at runtime.Click to reveal answer
beginner
What keyword is used in the base class method to allow overriding?The <code>virtual</code> keyword marks a method in the base class as overridable, enabling runtime polymorphism.Click to reveal answer
intermediate
What happens if you call a non-virtual method through a base class reference?The base class method is called, even if the derived class has a method with the same name. This is because non-virtual methods are resolved at compile time, not runtime.Click to reveal answer
beginner
Explain the role of the
override keyword in runtime polymorphism.The <code>override</code> keyword tells the compiler that the derived class method replaces the base class virtual method. This enables the runtime to call the correct method version based on the actual object type.Click to reveal answer
Which keyword in C# allows a method to be overridden for runtime polymorphism?
✗ Incorrect
The
virtual keyword marks a method as overridable, enabling runtime polymorphism.What keyword must a derived class method use to override a base class virtual method?
✗ Incorrect
The
override keyword is used in the derived class to replace the base class virtual method.If a method is not marked virtual, what happens when called through a base class reference?
✗ Incorrect
Non-virtual methods are resolved at compile time, so the base class method is called.
What determines which method is called in runtime polymorphism?
✗ Incorrect
The actual object type at runtime decides which overridden method is executed.
Which of these is NOT required for runtime polymorphism in C#?
✗ Incorrect
Static methods cannot be overridden and do not support runtime polymorphism.
Describe how runtime polymorphism works in C# with an example.
Think about how a base class pointer can call a method that behaves differently depending on the actual object.
You got /4 concepts.
Explain the difference between virtual and non-virtual methods in the context of runtime polymorphism.
Consider what happens when you call a method through a base class reference.
You got /4 concepts.