Commerce

Classes And Objects In C Sharp MCQs

Practice Classes And Objects In C Sharp MCQs for competitive exams.

Classes And Objects In C Sharp MCQs

Practice questions from this topic.

A type of class which does not have its own objects but acts as a base class for its subclass is known as?

  1. A. Static class
  2. B. Sealed class
  3. C. Abstract class
  4. D. None of the mentioned
Report Error

Choose the wrong statement about structures in C#.NET?

  1. A. Structures can be declared within a procedure
  2. B. Structures can implement an interface but they cannot inherit from another structure
  3. C. Structure members cannot be declared as protected
  4. D. A structure cannot be empty
Report Error

In Inheritance concept, which of the following members of base class are accessible to derived class members?

  1. A. static
  2. B. protected
  3. C. private
  4. D. shared
Report Error

What will be the output of the following C# code? class maths { public int fun(int ii) { return(ii > 0 ? ii :ii * -1); } public long fun(long ll) { return(ll > 0 ? ll :ll * -1); } public double fun( double dd) { return(dd > 0 ? dd :dd * -1); } } class Program { static void Main(string[] args) { maths obj = new maths(); int i = -25; int j ; long l = -100000l ; long m; double d = -12.34; double e; j = obj.fun(i); m = obj.fun(l); e = obj.fun(d); Console.WriteLine(j + " " + m + " " + e); Console.ReadLine(); } }

  1. A. 1 1 1
  2. B. 0 0 0
  3. C. 25 100000 12.34
  4. D. -25 -100000 -12.34
Report Error

What will be the output of the following C# code? static void Main(string[] args) { int y = 3; y++; if (y <= 5) { Console.WriteLine("hi"); Main(args); } Console.ReadLine(); }

  1. A. hi hi
  2. B. hi
  3. C. Stack overflow exception
  4. D. None of the mentioned
Report Error

What will be the output of the following C# code? enum letters { a, b, c } letters l; l = letters.a; Console.writeline(l);

  1. A. -1
  2. B. 0
  3. C. a
  4. D. letters.a
Report Error

What will be the output of the following C# code? static void Main(string[] args) { int []a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; func(ref a); Console.ReadLine(); } static void func(ref int[] x) { Console.WriteLine(" numbers are:"); for (int i = 0; i < x.Length; i++) { if (x[i] % 2 == 0) { x[i] = x[i] + 1; Console.WriteLine(x[i]); } } }

  1. A. numbers are : 2 4 6 8 10
  2. B. numbers are : 3 5 7 9 11
  3. C. numbers are : 2 3 4 5 6
  4. D. none of the mentioned
Report Error

Which operator among the following signifies the destructor operator?

  1. A. ::
  2. B. :
  3. C. ~
  4. D. &
Report Error

Which of these will happen if the recursive method does not have a base case?

  1. A. Infinite loop condition occurrence
  2. B. System gets hanged
  3. C. After 10000 executions program will be automatically stopped
  4. D. None of the mentioned
Report Error

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

  1. A. Result before swap is: 20 10 Result after swap is: 20 10
  2. B. Result before swap is: 10 20 Result after swap is:20 10
  3. C. Result before swap is: 10 20 Result after swap is:10 20
  4. D. Result before swap is: 20 10 Result after swap is:10 20
Report Error

What will be the output of the following C# code? class maths { public static void fun1() { Console.WriteLine("method 1 :"); } public void fun2() { fun1(); Console.WriteLine("method 2 :"); } public void fun2(int k) { Console.WriteLine(k); fun2(); } } class Program { static void Main(string[] args) { maths obj = new maths(); maths.fun1(); obj.fun2(20); Console.ReadLine(); } }

  1. A. method 1: method 2: 20 method 1:
  2. B. method 2: 20 method 1: method 1:
  3. C. method 1: 0 method 2: method 2:
  4. D. method 1: 20 method 1: method 2:
Report Error

Which of the following cannot be used to declare a class as a virtual?

  1. A. Methods
  2. B. Properties
  3. C. Events
  4. D. Fields
Report Error