hi, What is the difference between shadow and override Regards, Rakesh
Shadowing: It hides a base class member in the derived by using the "New" keyword. It is used to explicitly hide a member inherited from base class. new and override both cannot be used for the same member. eg:- class Employee { public virtual double CalculateSalary() { return basic_salary; } } class SalesPerson: Employee { double sales,comm; public new double CalculateSalary() { return basic_salary+(sales*comm); } } static void main(string[] args) { SalesPerson sal=new SalesPerson(); double s=sal.CalculateSalary(); Console.WriteLine(s); } Overriding:In this methods have same names,same signatures,same return types but in different classes.C# uses virtual and override keyword for method overriding. eg:- class Employee { public virtual double CalculateSalary() { return basic_salary; } } class SalesPerson: Employee { double sales,comm; public override double CalculateSalary() { return basic_salary+(sales*comm); } } static void main(string[] args) { Employee sal=new SalesPerson(); double s=sal.CalculateSalary(); Console.WriteLine(s); } When you call the derived class object with a base class variable.In class of overriding although you assign a derived class object to base class variable it will call the derived class function. In case of shadowing or hiding the base class function will be called.