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.

The method called by clients of a class to explicitly release any resources like network, connection, open files etc. When the object is no longer required?

  1. A. Finalize()
  2. B. End()
  3. C. Dispose()
  4. D. Close()
Report Error

Select the correct statement from the following?

  1. A. Static methods can be a virtual method
  2. B. Abstract methods can be a virtual method
  3. C. When overriding a method, the names and type signatures of the override method must be the same as the virtual method that is being overridden
  4. D. We can override virtual as well as nonvirtual methods
Report Error

What will be the output of the following C# code? class maths { public int fun(int k, int y) { return k + y; } public int fun1(int t, float z) { return (t+(int)z); } } class Program { static void Main(string[] args) { maths obj = new maths(); int i; int b = 90; int c = 100; int d = 12; float l = 14.78f; i = obj.fun(b, c); Console.WriteLine(i); int j = (obj.fun1(d, l)); Console.WriteLine(j); Console.ReadLine(); } }

  1. A. 190, 26.78f
  2. B. 0, 26.78f
  3. C. 190, 26
  4. D. 190, 0
Report Error

Correct way to define object of sample class in which C# code will work correctly is: class abc { int i; float k; public abc(int ii, float kk) { i = ii; k = kk; } }

  1. A. abc s1 = new abc(1)
  2. B. abc s1 = new abc()
  3. C. abc s2 = new abc(1.4f)
  4. D. abc s2 = new abc(1, 1.4f)
Report Error

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

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

Choose the correct statement among the below mentioned statements.

  1. A. Forgetting to declare an operator method as public
  2. B. Forgetting to declare an operator method as static
  3. C. Forgetting to return a bool type value while overloading a relational operator
  4. D. All of the mentioned
Report Error

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

  1. A. 6 7 8 9 10
  2. B. 15 17 8 8 20
  3. C. 15 17 8 29 20
  4. D. Syntax error while passing reference of array variable
Report Error

Which of the following modifiers is used when an abstract method is redefined by a derived class?

  1. A. Overloads
  2. B. Override
  3. C. Base
  4. D. Virtual
Report Error

Correct statement about constructors in C#.NET is?

  1. A. Constructors can be overloaded
  2. B. Constructors are never called explicitly
  3. C. Constructors have same name as name of the class
  4. D. All of the mentioned
Report Error

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

  1. A. 24
  2. B. 30
  3. C. 120
  4. D. 144
Report Error

Wrong statement about run time polymorphism is?

  1. A. The overridden base method should be virtual, abstract or override
  2. B. An abstract method is implicitly a virtual method
  3. C. An abstract inherited property cannot be overridden in a derived class
  4. D. Both override method and virtual method must have same access level modifier
Report Error

Which method has the same name as that of its class?

  1. A. delete
  2. B. class
  3. C. constructor
  4. D. none of the mentioned
Report Error