C# Classes and Objects Mcqs

Our collections of Multiple choice questions and answers focuses on study of C# Classes and Objects. These questions are chosen from a collection of most authoritative and best reference books on C# Classes and Objects. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate C# Classes and Objects comprehensively.

  1. Home
  2. »
  3. Languages
  4. »
  5. Programming Languages Mcqs
  6. »
  7. C# Programming Mcqs
  8. »
  9. Classes and Objects Mcqs
  10. »
  11. Page 3

31.
Select output for the following set of 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();
     }
 }

Sample.fun(1, 5) will not work correctly

S.i = 10 cannot work as i is ‘public’

Sample.fun(1, 5) will set value as 5 in arr[1].

S.fun(1, 5) will work correctly

35.
Select the output for the following set of 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();
      }
  }

Error while calling s.fun() due to inaccessible level

Error as ‘this’ reference would not be able to call ‘i’ and ‘j’

1 2

Runs successfully but prints nothing

36.
Which of following statements about objects in “C#” is correct?

Everything you use in C# is an object, including Windows Forms and controls

Objects have methods and events that allow them to perform actions

All objects created from a class will occupy equal number of bytes in memory

All of the mentioned

37.
“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 the access to that particular code and data.”

Abstraction

Polymorphism

Inheritance

Encapsulation

38.
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();
      }
   }

10 20
5 25

20 10
25 5

10 20
5 125

20 10
125 5

41.
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();
      }
  }

Syntax error

{0} is in city{1} harsh new delhi

Harsh is in new delhi

Run successfully prints nothing

42.
What does the following code imply ?
csharp abc;
abc = new charp();

Object creation on class csharp

Create an object of type csharp on heap or on stack depending on the size of object

Create a reference c on csharp and an object of type csharp on heap

Create an object of type csharp on stack

43.
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();
       }
   }

Code runs successfully prints nothing

Code runs and prints “Csharp”

Syntax error as t is unassigned variable which is never used

None of the mentioned

45.
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;
    }

5

0

20

25

error: You are not allowed to do so.....
0Shares
0
Scroll to Top