Can Function Overriding be defined in Same Class?

 Posted by vishalneeraj-24503 on 11/29/2013 | Category: OOPS Interview questions | Views: 1034 | Points: 40
Answer:

No,Function Overriding can only be defined in different class because it treated as Base and Derived or parent-child relationship.

We can understand it by an example:-

public class Base_Class

{
public Base_Class()
{
}

public virtual void display()
{
Console.WriteLine("base class");
}
}

public class Derive_Class:Base_Class
{
public Derive_Class()
{

}

public override void display()
{
Console.WriteLine("derive class");
}
}


Note:- The Override keyword is used in Function Overriding to override methods.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response