Multiple choice

What is the error in the following code, if any? using System;class Demo { private string name; public void print() { Console.WriteLine(nMy name is + name); } public string Name { get { return name; } set { name = value; } } class Program { static void Main(string[] args) { Demo d = new Demo(); Console.Write(Enter your name:t); d.name = Console.ReadLine(); d.print(); Console.ReadLine(); } } }

  1. Private variable is not accessible in subclass.

  2. There is a syntax error in get property.

  3. It will give exception.

  4. The code will compile with no error.

  5. None of the above

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

Yes, It will compile properly as we get and set the property for the private variable so it is accessible now in subclass too.