My Report

C# Classes Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C# 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();
      }
   }
 

2. What does the following C# code imply?

      csharp abc;
      abc = new charp();

3. Which of the following statements about objects in "C#" is correct?

4. The operator used to access member function of a class?

5. What will be the output of the following C# code?

  class sample
  {
      public int i;
      public int j;
      public void fun(int i, int j)
      {
          this.i = i;
          this.j = j;
      }
  }
  class Program
  {
      static void Main(string[] args)
      {
          sample s = new sample();
          s.i = 1;
          s.j = 2;
          s.fun(s.i, s.j);
          Console.WriteLine(s.i + " " + s.j);
          Console.ReadLine();
      }
  }
 

6. Which of the following is used to define the member of a class externally?

7. What will be the output of the following C# code?

  class z
  {
      public string name1;
      public string address;
      public void show()
      {
          Console.WriteLine("{0} is in city{1}", name1, " ", address);
      }
  }
  class Program
  {
      static void Main(string[] args)
      {
          z n = new z();
          n.name1 = "harsh";
          n.address = "new delhi";
          n.show();
          Console.ReadLine();
      }
  }
 

8. What will be the output of the following C# code?

   
 class sample
 {
     public int i;
     public int[] arr = new int[10];
     public void fun(int i, int val)
     {
         arr[i] = val;
     }
 }
 class Program
 {
     static void Main(string[] args)
     {
         sample s = new sample();
         s.i = 10;
         sample.fun(1, 5);
         s.fun(1, 5);
         Console.ReadLine();
     }
 }
 

9. What will be the output of the following C# code?

   class test
   {
       public void print()
       {
           Console.WriteLine("Csharp:");
       }
   }
   class Program
   {
       static void Main(string[] args)
       {
           test t;
           t.print();
           Console.ReadLine();
       }
   }
 

10. What is the most specified using class declaration?

11. Correct way of declaration of object of the following class is?

 class name

12. The data members of a class by default are?

13. "A mechanism that binds together code and data in manipulates, and keeps both safe from outside interference and misuse. In short it isolates a particular code and data from all other codes and data. A well-defined interface controls access to that particular code and data."


 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.