0
0
C Sharp (C#)programming~5 mins

Virtual method dispatch mechanism in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the virtual method dispatch mechanism in C#?
It is the process where the program decides at runtime which version of a virtual method to call, based on the actual object's type, not the reference type.
Click to reveal answer
beginner
How do you declare a method as virtual in C#?
By using the virtual keyword before the method return type in the base class.
Click to reveal answer
beginner
What keyword is used to override a virtual method in a derived class?
The override keyword is used to provide a new implementation of a virtual method in a derived class.
Click to reveal answer
intermediate
Why is virtual method dispatch important in object-oriented programming?
It enables polymorphism, allowing objects of different classes to be treated uniformly while invoking their specific behaviors at runtime.
Click to reveal answer
intermediate
What happens if a method is not declared virtual but is redefined in a derived class?
The method in the derived class hides the base class method, but calls are resolved at compile time based on the reference type, not the object type.
Click to reveal answer
Which keyword in C# allows a method to be overridden in derived classes?
Avirtual
Boverride
Cnew
Dabstract
What determines which method implementation is called when using virtual methods?
AThe object type at runtime
BThe reference type
CThe method name only
DThe compiler settings
If a base class method is not virtual, what happens when a derived class defines a method with the same name?
AThe derived method overrides the base method
BThe base method is called always
CA compile error occurs
DThe derived method hides the base method
Which keyword must be used in the derived class to provide a new implementation of a virtual method?
Avirtual
Bnew
Coverride
Dsealed
What is the main benefit of virtual method dispatch?
AFaster code execution
BRuntime polymorphism
CCompile-time method selection
DMemory optimization
Explain how virtual method dispatch works in C# with an example.
Think about a base class with a virtual method and a derived class overriding it.
You got /4 concepts.
    Describe the difference between method overriding and method hiding in C#.
    Consider what happens when the base method is virtual or not.
    You got /4 concepts.