brief what virtual void means | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

4th Jun 2017, 10:24 PM
ALAMOUDI, WAEL MAKKI S
ALAMOUDI, WAEL MAKKI S - avatar
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/
4th Jun 2017, 10:30 PM
jay
jay - avatar