What will be the output of the following C# code? [code] class z { public int X; public int Y; public const int

Thê Hy

New member
What will be the output of the following C# code?
Code:
  class z
  {
      public int X;
      public int Y;
      public  const int c1 = 5;
      public  const int c2 = c1 * 25;
      public void set(int a, int b)
      {
          X = a;
          Y = b;
      }
  }
  class Program
  {
      static void Main(string[] args)
      {
          z s = new z();
          s.set(10, 20);
          Console.WriteLine(s.X + " " + s.Y);
          Console.WriteLine(z.c1 + " " + z.c2);
          Console.ReadLine();
      }
   }
A.
10 20
5 25
B.
20 10
25 5
C.
10 20
5 125
D.
20 10
125 5
 
Answer: c
Explanation: Member function() ‘set’ is accessed using object of class ‘z’ values are passed as parameter to ‘a’ and ‘b’. Since, variable ‘c1’ and ‘c2’ are public data member of class ‘z’. They are accessed using classname.
Output :
Code:
           10 20
           5  125
 

Tìm kiếm

Back
Top