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

expert

What is a preprocessor directives in C#?

middle

What is scope of a Internal member variable of a C# class?

senior

What is the difference between dispose and finalize methods in C#?

Bình luận

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

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