Multiple choice

Which of the following code(s) has error?

  1. using System;using System.Collections.Generic;class A{ public void Demo() { Console.WriteLine(The Demo is called); }} class Test { static void Main(string[] args) { A a=new A(); a.Demo(); } }

  2. using System;using System.Collections.Generic;class A{ protected void Demo() { Console.WriteLine(The Demo is called); }} class Test { static void Main(string[] args) { A a=new A(); a.Demo(); } }

  3. using System;using System.Collections.Generic;class A{ protected void Demo() { Console.WriteLine(The Demo is called);}}class B:A { public B() { Demo(); } static void Main(string[] args) { B b=new B(); } }

  4. none of the above

  5. both (2) and (3)

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

This code will give compile error protected members can be accesses either in the same class or in the base class of that class. These protected members cannot be accessed outside the class.