Domanda di colloquio di Mindfire Solutions

overide method and overload method

Risposta di colloquio

Anonimo

3 giu 2019

Method Overloading: Method overloading is also called early binding or compile-time polymorphism or static binding. The compiler automatically calls the required method or the function by checking a number of parameters and their type, which are passed into that method. If the number of parameters and type doesn't match by any method signatures, then it will give the compile-time error. We can achieve method overloading by changing the number of parameters used or by using different types of parameters or by changing the order of parameters Method Overriding: Method overriding means having two methods with the same name and same signature, one method in the base class and the other method in the derived class. Key points Method overriding is also called run time polymorphism or dynamic polymorphism or late binding. We can override a method in the base class by creating a similar function in the derived class. This can be achieved by using inheritance and using virtual & override. The same signature means the methods must have the same name, the same number of arguments and the same type of arguments. Method overriding is possible only in the derived classes, but not within the same class. When the derived class needs a method with the same signature as in the base class but wants to execute different code than the one provided by the base class then method overriding will be used.

2