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:

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:

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

senior

What is the best practice to have best performance using Lazy objects?

senior

Can Multiple Inheritance implemented in C# ?

junior

Why to use finally block in C#?

Bình luận

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

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