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

What is the difference between Virtual method and Abstract method?

Câu trả lời

Here is the difference between virtual methods and abstract methods in C#:

Virtual Methods

  • Virtual methods are implemented in a base class and can be overridden in derived classes.
  • The base class implementation provides a default behavior that can be used if a derived class does not override the method.
  • If a derived class overrides a virtual method, it provides its own implementation that replaces the inherited implementation.
  • Virtual methods allow for polymorphism, where objects of a derived class can be treated as objects of the base class and the correct method is called at runtime based on the actual type of the object.
  • The virtual keyword is used to mark a method as virtual in the base class.
  • The override keyword is used to override a virtual method in a derived class.

Abstract Methods

  • Abstract methods are declared in an abstract base class but hav...
middle

middle

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

middle

What is a Destructor in C# and when shall I create one?

expert

List some different ways for equality check in .NET

expert

What's the difference between the System.Array.CopyTo() and System.Array.Clone() ?

Bình luận

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

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