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 abc { public static void a() { console.writeline("first method"); } public void b() { a(); console.writeline("second method"); } public void b(int i) { console.writeline(i); b(); } } class program { static void main() { abc k = new abc(); abc.a(); k.b(20); } }

  1. A. second method 20 second method first method
  2. B. first method 20 first method second method
  3. C. first method 20
  4. D. second method 20 first method
Report Error

What will be the output of the following C# code? class sample { public int i; void display() { Console.WriteLine(i); } } class sample1 : sample { public int j; public void display() { Console.WriteLine(j); } } class Program { static void Main(string[] args) { sample1 obj = new sample1(); obj.i = 1; obj.j = 2; obj.display(); Console.ReadLine(); } }

  1. A. 1
  2. B. 3
  3. C. 2
  4. D. Compile Time error
Report Error

What will be the output of the following C# code? class a { public void fun() { Console.WriteLine("base method"); } } class b: a { public new void fun() { Console.WriteLine(" derived method "); } } class Program { static void Main(string[] args) { b k = new b(); k.fun(); Console.ReadLine(); } }

  1. A. Base method
  2. B. Derived method
  3. C. Code runs successfully prints nothing
  4. D. Compile time error
Report Error

Which among the following differentiates enum in C#.NET from enum in C language?

  1. A. C is strictly a typed language, C#.NET also is a strictly typed language
  2. B. In C, language variables of enum types can be used interchangeably with integers using type casts while enum variables cannot be used as a normal integers in C#.NET
  3. C. None of the mentioned
  4. D. All of the mentioned
Report Error

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

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

Which form of inheritance is not supported directly by C# .NET?

  1. A. Multiple inheritance
  2. B. Multilevel inheritance
  3. C. Single inheritance
  4. D. Hierarchical inheritance
Report Error

Which of the following statements are correct in nature?

  1. A. The conditional logical operators cannot be overloaded
  2. B. The array indexing operator can be overloaded
  3. C. A public or nested public preference type does not overload the equality operator
  4. D. None of the mentioned
Report Error

What will be the Correct statement in the following C# code? interface a1 { void f1(); int f2(); } class a :a1 { void f1() { } int a1.f2() { } }

  1. A. class a is an abstract class
  2. B. A method table would not be created for class a
  3. C. The definition of f1() in class a should be void a1.f1()
  4. D. None of the mentioned
Report Error

What will be the output of the following C# code? class maths { public int x; public double y; public int add(int a, int b) { x = a + b; return x; } public int add(double c, double d) { y = c + d; return (int)y; } public maths() { this.x = 0; this.y = 0; } } class Program { static void Main(string[] args) { maths obj = new maths(); int a = 4; double b = 3.5; obj.add(a, a); obj.add(b, b); Console.WriteLine(obj.x + " " + obj.y); Console.ReadLine(); } }

  1. A. 4, 3.5
  2. B. 8, 0
  3. C. 7.5, 8
  4. D. 8, 7
Report Error

Select the wrong statements among the following?

  1. A. A structure can contain properties
  2. B. A structure can contain constructors
  3. C. A structure can contain protected data members
  4. D. A structure can contain constants
Report Error

What will be the output of the following C# code? class sample { public sample() { Console.WriteLine("THIS IS BASE CLASS constructor"); } } public class sample1 : sample { } class Program { static void Main(string[] args) { sample1 obj = new sample1(); Console.ReadLine(); } }

  1. A. Code executes successfully prints nothing
  2. B. This is base class constructor
  3. C. Compile time error
  4. D. None of the mentioned
Report Error

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

  1. A. 11
  2. B. 1
  3. C. 2
  4. D. compile time error
Report Error