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 the use of the IDisposable interface?

middle

Why can't you specify the accessibility modifier for methods inside the Interface?

expert

What is jagged array in C# and when to prefer jagged arrays over multi-dimensional arrays?

Bình luận

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

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