Jul 20, 2015

how can we override method in child class without using “virtual” in parent class

They probably wanted you to say "Use the new keyword to hide the method." Which technically does not override the method. If you have
class Base
{
    public void Bar() { Console.WriteLine("Base"); }
}

class Derived : Base
{
    public new void Bar() { Console.WriteLine("Derived"); }
}

No comments:

Post a Comment