Sobes.tech
Junior — Senior

What lines will be printed in the console

livecode

Task condition

In the example, two classes are declared:

  • ClassA contains a virtual method Test() and a constructor in which this method is called.
  • ClassB inherits from ClassA and overrides the Test() method. Also, in its constructor, it calls Test(). What output will appear in the console when creating an instance of ClassB?
public class ClassA
{
    public ClassA()
    {
        Test()
    }

    public virtual void test()
    {
        Console.WriteLine("AAA");
    }
}

public class ClassB : ClassA
{
    public ClassB()
    {
        Test();
    }

    public override void Test()
    {
        Console.WriteLine("BBB");
    }
}

public class Main()
{
    Main()
    {
        classB t = new();
    }
}