Logo 
Search:

C# Forum

Ask Question   UnAnswered
Home » Forum » C#       RSS Feeds

Example for Virtual Override keyword in C#

  Asked By: Carole    Date: Dec 19    Category: C#    Views: 2016
  

I am looking for Example for Virtual Override keyword used in C# program.

Can anyone provide me sample class example with making use of Virtual and Override Keyword used!

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Adanalie Garcia     Answered On: Dec 19

//The virtual  keyword is used to modify a method, property, indexer or event declaration,
//and allow it to be overridden in a derived class

class Class1
{
static void Main(string[] args)
{
Foo b1 = new Bar();
b1.Response();
Console.ReadLine();
}
}
abstract class  Foo
{
public virtual void Response()
{
Console.WriteLine("In Foo");
}
}
class Bar : Foo
{
public new void Response()
{
Console.WriteLine("In Bar");
}
}

//Output
//In Foo

 
Didn't find what you were looking for? Find more on Example for Virtual Override keyword in C# Or get search suggestion and latest updates.
This post is locked for further answers.




Tagged: