Home »
MCQs »
C# MCQs
What will be the output of the following C# code? | Question 20
82. What will be the output of the following C# code?
using System;
namespace MyApplication {
public class Class1 {
public static int x = 10;
}
public class Class2: Class1 {
public static int x = 20;
static void Main(string[] args) {
Console.WriteLine(x + ", " + Class1.x);
}
}
}
- 20, 20
- 10, 10
- 20, 10
- Exception
Answer: C) 20, 10
Explanation:
In the above code, we are printing the values of x which is the member of Class2 and Class1.x which is the member of Class1. Thus, the output will be "20, 10".