Answered! C# programmin language – What is a virtual function? Give a complete code example as part of your response….

C# programmin language – What is a virtual function? Give a complete code example as part of your response. Appropriate examples include the Doodle application done with the OnPaint method or any example that uses the OnPaint method or an ovveride of a function that does not exhibit polymorphic behavior.aaaaaaqqqqqqqqqqqqqqqq

Expert Answer

 A virtual function is a function that can be overridden in a derived class using the override keyword, the behavior ofnthis overidden function can be different than in superclass. If this function is overriden then the original function in superclass will be called.

Example

public class ParentClass
{
public void display()
{
Console.WriteLine(“Hello World”);
}

public virtual void v_display()
{
Console.WriteLine(“Virtual in parent”);
}

}

public class ChildClass : ParentClass
{
public new void display()
{
Console.WriteLine(“Hi There”);
}

public override void v_display()
{
Console.WriteLine(“Overidden display”);
}
}

when an object of ChildClass is instantiated any call to v_display() will display Overidden Display

Still stressed from student homework?
Get quality assistance from academic writers!