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.

When we call a constructor method among different given constructors. We match the suitable constructor by matching the name of constructor first, then the number and then the type of parameters to decide which constructor is to be overloaded. The process is also known as?

  1. A. Method overriding
  2. B. Inheritance
  3. C. Polymorphism
  4. D. Encapsulation
Report Error

What will be the output of the following C# code? class maths { int fact(int n) { int result; if (n == 1) return 1; result = fact(n - 1) * n; return result; } } class Output { static void main(String args[]) { maths obj = new maths() ; Console.WriteLine(obj.fact(4)*(3)); } }

  1. A. 64
  2. B. 60
  3. C. 72
  4. D. 84
Report Error

Select the correct statement among the given statements?

  1. A. One class could implement only one interface
  2. B. Properties could be declared inside an interface
  3. C. Interfaces cannot be inherited
  4. D. None of the mentioned
Report Error

Correct statement about constructor overloading in C# is?

  1. A. Overloaded constructors have the same name as the class
  2. B. Overloaded constructors cannot use optional arguments
  3. C. Overloaded constructors can have different type of number of arguments as well as differ in number of arguments
  4. D. All of the mentioned
Report Error

The modifier used to define a class which does not have objects of its own but acts as a base class for its subclass is?

  1. A. Sealed
  2. B. Static
  3. C. New
  4. D. Abstract
Report Error

What will be the output of the following C# code? class sample { int i; double k; public sample (int ii, double kk) { i = ii; k = kk; double j = (i) + (k); Console.WriteLine(j); } ~sample() { double j = i - k; Console.WriteLine(j); } } class Program { static void Main(string[] args) { sample s = new sample(8, 2.5); Console.ReadLine(); } }

  1. A. 0 0
  2. B. 10.5 0
  3. C. Compile time error
  4. D. 10.5 5.5
Report Error

Which of these operators must be used to inherit a class?

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

Select the wrong statement about 'ref' keyword in C#?

  1. A. References can be called recursively
  2. B. The 'ref' keyword causes arguments to be passed by reference
  3. C. When 'ref' are used, any changes made to parameters in method will be reflected in variable when control is passed back to calling method
  4. D. All of the mentioned
Report Error

A class member declared protected becomes member of subclass of which type?

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

The number of levels of inheritance are?

  1. A. 5
  2. B. 4
  3. C. 3
  4. D. 2
Report Error

What is the vector in operator overloading?

  1. A. class
  2. B. method()
  3. C. data type
  4. D. none of the mentioned
Report Error

What will be the output of the following C# code? class maths { public int fun1(int k) { k = 20; return k; } public Single fun1(float t) { t = 3.4f; return t; } } class Program { static void Main(string[] args) { maths obj = new maths(); int i; i = obj.fun1(30); Console.WriteLine(i); Single j; j = obj.fun1(2.5f); Console.WriteLine(j); Console.ReadLine(); } }

  1. A. 30 2.5f
  2. B. 2.5f 30
  3. C. 20 2.5f
  4. D. 20 3.4f
Report Error