methodOverridingquiz.md - brainchildservices/curriculum GitHub Wiki

  1. What is method overriding?

    • The process of re-implementing a base class non-static method in the derived class with the same signature as defined in the superclass is called Function Overriding or Method Overriding in C#.
  2. When do we need to override a method in C#?

    • If the base class method logic is not fulfilling the derived business requirements, then the derived class needs to override that method with the required business logic.
  3. How to achieve method overriding?

    • In order to override a method: You need to add virtual keyword to the method in the base class. You need to add override keyword to the same method in the derived class. Create an object of derived class with reference to the base class.
  4. What is runtime polymorphism?

    • Whenever an object is bound with the functionality at run time, this is known as runtime polymorphism.
  5. What happens when the derived class and base class has the same member name?

    • You get a warning message that the derived class members override the base class members.
  6. What is method hiding?

    • When the base class and derived class both have the same method name and signature, the compiler automatically hides the method in base class and gives out a warning message. Adding the new keyword to the method in derived class would explicitly hide the base class method and remove the warning message. This is called method hiding.
  7. What does the base keyword do?

    • Base keyword is used to access the members of the base class in the derived class that have been overridden or hidden.
  8. Define use of method overriding.

    • It is used in order to change the behavior of exist methods.