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

What is the difference between overloading and overriding?

Câu trả lời

Here is the difference between method overloading and method overriding in C#:

Method Overloading

  • Overloading allows you to define multiple methods with the same name but different parameters within the same class.
  • The methods must differ in the number, types, or order of parameters.
  • Overloaded methods are resolved at compile-time based on the arguments passed to the method call.
  • Overloading allows you to provide multiple implementations of a method to handle different scenarios.
  • Overloading is a compile-time polymorphism feature.

Example:

csharp Copy
public class Calculator
{
    public int Add(int a, int b)
    {
        return a + b;
    }

    public int Add(int a, int b, int c)
    {
        return a + b + c;
    }
}

Method Overriding

  • Overriding allows you to provide a specific implementation of a method that is already defined in the base class.
  • The method in the derived class mu...
middle

middle

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

senior

What is the difference between Func<string,string> and delegate ?

expert

Why Abstract class can not be sealed or static?

expert

What are Circular References in C#?

Bình luận

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

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