×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

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);
    }
  }
}
  1. 20, 20
  2. 10, 10
  3. 20, 10
  4. 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".

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.