Multiple choice

What will be the output of the following code? using System;class A { public void DemoA() { Console.WriteLine(Method of class A); } } class B : A { public void DemoB() { Console.WriteLine(Method of class B); } } class Test { static void Main (string[] args) { A a=new B(); a.DemoA(); a.DemoB(); } }

  1. Method of class AMethod of class B

  2. Method of class BMethod of class B

  3. Method of class AMethod of class A

  4. Compilation error

  5. None of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The code will not compile as we have an object of type B but base class A does not have the definition of method DemoB of the B class. Hence a.DemoB() is illegal but a.DemoA() is legal.