Click here to Skip to main content
16,012,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
You have one base class virtual function how will you call from derieved class
Posted

see below
C#
public class Base
{
   public Base(){}
   public virtual void show(string message)
   {
      //Your Logic
   }
}

public class Derived
{
// Only if  you want to override base class show method
   public override void show(string message)
   {
      //Your Logic to override 
   }
}

public class CallFunction
{
    public static void Main()
    {
       Derived obj = new Derived()
       obj.show("Hii");
    }
}
 
Share this answer
 
Hello,

A virtual method can be redefined. In the C# language, the virtual keyword designates a method that can be overridden in derived classes. This enables you to add new, derived types without modifying the rest of your program. The runtime type of objects thus determines what your program does.

Have a look at following examples, hope you will understand.
http://www.vijaymukhi.com/documents/books/csbasics/chap9.htm[^]
http://www.akadia.com/services/dotnet_polymorphism.html[^]
http://www.dotnetperls.com/virtual[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900