0
brief what virtual void means
class A { public void F() { Console.WriteLine("A.F"); } public virtual void G() { Console.WriteLine("A.G"); } } class B : A { new public void F() { Console.WriteLine("B.F"); } public override void G() { Console.WriteLine("B.G"); } } class Program { static void Main(string[] args) { B b = new B(); A a = b; a.G(); b.G(); it is print "B.G" twice .why and virtual what does
1 Answer
+ 5
Virtual allows for a derived function to overwrite the functionality of a base members function.
it prints b.g twice because a=b;
here: http://www.cplusplus.com/doc/tutorial/polymorphism/