What Will Be The Output Of The Following C Codep Pre Langcsharp #477
What will be the output of the following C# code?</p> <pre><code class="language-csharp" line="1"> class number { private int num1; private int num2; public int anumber { get { return num1; } set { num1 = value; } } public int anumber1 { get { return num2; } set { num2 = value; } } } class Program { public static void Main(string[] args) { number p = new number(); p.anumber = 20; number k = new number(); k.anumber1 = 40; int m = p.anumber; int t = k.anumber1; int r = p.anumber + k.anumber1; System.Console.WriteLine("number1 = " +m); System.Console.WriteLine("number2 = " +t); System.Console.WriteLine("sum = " +r); System.Console.ReadLine(); } } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs108 CSharp. It can also be found in gs gs108 Indexers and Exception Handling - Properties and its Applications - Quiz No.1.
What will be the output of the following C# code?
class number { private int num1; private int num2; public int anumber { get { return num1; } set { num1 = value; } } public int anumber1 { get { return num2; } set { num2 = value; } } } class Program { public static void Main(string[] args) { number p = new number(); p.anumber = 20; number k = new number(); k.anumber1 = 40; int m = p.anumber; int t = k.anumber1; int r = p.anumber + k.anumber1; System.Console.WriteLine("number1 = " +m); System.Console.WriteLine("number2 = " +t); System.Console.WriteLine("sum = " +r); System.Console.ReadLine(); } }
20
number1 = 30 number2 = 40 sum = 70
number1 = 20 number2 = 40 sum = 60
Compile time error