Can you declare the override method as static while the original method is non-static ?

 Posted by Akiii on 5/9/2011 | Category: C# Interview questions | Views: 17561 | Points: 40
Answer:

No, you cannot, the signature of the virtual method must remain the same, only the keyword "virtual" is changed to keyword "override" .

//Base Class

Public Class BaseClass
{
public virtual string Name()
{
return "my name";
}
}


//Derived Class

Public Class DerivedClass: BaseClass
{
public override string Name()
{
return "my name is Akiii";
}
}




Thanks and Regards
Akiii


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Kishork80 on: 5/10/2011 | Points: 10
Override is used as a polymorphism and is only attached to an instance of a class. Static is ONLY associated with class and can not help in polymorphism. so virtual can not be applied to Static.
Posted by: Shoeb2222 on: 6/22/2011 | Points: 10
Method overriding is giving new definition to the method (present in base class) in the derived class. It must have the same signature, otherwise you will get compile time error.

Thanks & Regards,
Shoeb

Login to post response