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.

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

  1. A. Code runs successfully prints nothing
  2. B. Code runs and prints "Csharp"
  3. C. Syntax error as t is unassigned variable which is never used
  4. D. None of the mentioned
Report Error

Which keyword is used to refer baseclass constructor to subclass constructor?

  1. A. This
  2. B. Static
  3. C. Base
  4. D. Extend
Report Error

What will be the output of the following C# code? class maths { int i; public maths(int ii) { ii = 12; int j = 12; int r = ii * j; Console.WriteLine(r); } } class maths1 : maths { public maths1(int u) :base(u) { u = 13; int h = 13; Console.WriteLine(u + h); } } class maths2 : maths1 { public maths2(int k) :base(k) { k = 24; int o = 6 ; Console.WriteLine(k /o); } } class Program { static void Main(string[] args) { maths2 t = new maths2(10); Console.ReadLine(); } }

  1. A. 4, 26, 144
  2. B. 26, 4, 144
  3. C. 144, 26, 4
  4. D. 0, 0, 0
Report Error

What is Recursion in CSharp defined as?

  1. A. Recursion is another form of class
  2. B. Recursion is another process of defining a method that calls other methods repeatedly
  3. C. Recursion is a process of defining a method that calls itself repeatedly
  4. D. Recursion is a process of defining a method that calls other methods which in turn calls this method
Report Error

Calculate the number of bytes a structure variable s occupies in the memory if it is defined as follows. class abc { int i; Decimal d; } struct sample { private int x; private Single y; private trial z; } sample s = new sample();

  1. A. 24 bytes
  2. B. 8 bytes
  3. C. 16 bytes
  4. D. 12 bytes
Report Error

To override a method in the subclass, the base class method should be defined as?

  1. A. Virtual
  2. B. Abstract
  3. C. Override
  4. D. All of the mentioned
Report Error

"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."

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

What will be the output of the following C# code? class maths { int i; public maths(int x) { i = x; Console.WriteLine(" hello: "); } } class maths1 : maths { public maths1(int x) :base(x) { Console.WriteLine("bye"); } } class Program { static void Main(string[] args) { maths1 k = new maths1(12); Console.ReadLine(); } }

  1. A. hello bye
  2. B. 12 hello
  3. C. bye 12
  4. D. Compile time error
Report Error

Which reference modifier is used to define reference variable?

  1. A. &
  2. B. ref
  3. C. #
Report Error

What will be the output of the following C# code? class overload { public int x; int y; public int add(int a) { x = a + 1; return x; } public int add(int a, int b) { x = a + 2; return x; } } class Program { static void Main(string[] args) { overload obj = new overload(); overload obj1 = new overload(); int a = 0; obj.add(6); obj1.add(6, 2); Console.WriteLine(obj.x); Console.WriteLine(obj1.x); Console.ReadLine(); } }

  1. A. 8 8
  2. B. 0 2
  3. C. 8 10
  4. D. 7 8
Report Error

Choose the correct statements among the following:

  1. A. An abstract method does not have implementation
  2. B. An abstract method can take either static or virtual modifiers
  3. C. An abstract method can be declared only in abstract class
  4. D. All of the mentioned
Report Error

A class consists of two interfaces with each interface consisting of three methods. The class had no instance data. Which of the following indicates the correct size of object created from this class?

  1. A. 12 bytes
  2. B. 16 bytes
  3. C. 0 bytes
  4. D. 24 bytes
Report Error