adplus-dvertising

Welcome to the Classes and Objects MCQs Page

Dive deep into the fascinating world of Classes and Objects with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Objects, a crucial aspect of C# Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Objects, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C# Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Classes and Objects. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C# Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Classes and Objects. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Classes and Objects MCQs | Page 5 of 10

Explore more Topics under C# Programming

Q41.
Select the output for the following set of 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();
      }
   }
Discuss
Answer: (c).10 20
5 125
Q42.
Correct way of declaration of object of the following class is ?

class name
Discuss
Answer: (a).name n = new name();
Q43.
The data members of a class by default are ?
Discuss
Answer: (c).private
Q44.
Select the output for the following set of 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();
      }
  }
Discuss
Answer: (c).harsh is in new delhi
Discuss
Answer: (c).create a reference c on csharp and an object of type csharp on heap
Q46.
The output of code is ?
class test
   {
       public void print()
       {
           Console.WriteLine("Csharp:");
       }
   }
   class Program
   {
       static void Main(string[] args)
       {
           test t;
           t.print();
           Console.ReadLine();
       }
   }
Discuss
Answer: (c).Syntax error as t is unassigned variable which is never used
Q47.
Which refrence modifier is used to define reference variable?
Discuss
Answer: (b).ref
Q48.
Select the output for following set of code :
static void Main(string[] args)
   {
       int a = 5;
       fun1 (ref a);
       Console.WriteLine(a);
       Console.ReadLine();
    }
    static void fun1(ref int a)
    {
        a = a * a;
    }
Discuss
Answer: (d).25
Q49.
Select the output for the following set of code :
static void Main(string[] args)
 {
     int[] arr = new int[] {1 ,2 ,3 ,4 ,5 };
     fun1(ref arr);
     Console.ReadLine();
  }
 static void fun1(ref int[] array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = array[i] + 5;
         Console.WriteLine(array[i] + " ");
     }
 }
Discuss
Answer: (a).6 7 8 9 10
Q50.
Select the output for the following set of code :
static void Main(string[] args)
  {
      int a = 10 , b = 20;
      Console.WriteLine("Result before swap is: "+ a +" "+b);
      swap(ref a, ref b);
      Console.ReadLine();
  }
  static void swap(ref int i, ref int j)
  {
      int t;
      t = i;
      i = j;
      j = t;
      Console.WriteLine("Result after swap is:"+ i +" "+j);
  }
Discuss
Answer: (b).Result before swap is: 10 20
Result after swap is:20 10
Page 5 of 10

Suggested Topics

Are you eager to expand your knowledge beyond C# Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!