Câu hỏi phỏng vấn C#
Câu hỏi

What is Virtual Method in C#?

Câu trả lời

Virtual Method in C#

A virtual method in C# is a method that can be overridden in derived classes. It allows for polymorphism, which is the ability of objects of different classes to respond to the same method call in different ways.

Here are the key points about virtual methods in C#:

Definition and Syntax

To define a virtual method in a base class, you use the virtual keyword followed by the method signature:

csharp Copy
public virtual returnType MethodName(parameters)
{
    // method implementation
}

Overriding in Derived Classes

In a derived class, you can override the virtual method using the override keyword:

csharp Copy
public override returnType MethodName(parameters)
{
    // overridden method implementation
}

Late Binding and Dynamic Dispatch

When a virtual method is called on an object, the runtime determines which implementation of the method to execute based on the actual type of the...

middle

middle

Gợi ý câu hỏi phỏng vấn

middle

How can you prevent a class from overriding in C#?

junior

What are partial classes?

junior

Can this be used within a Static method?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào