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? namespace ConsoleApplication4 { class A { public int i; public void display() { Console.WriteLine(i); } } class B: A { public int j; public void display() { Console.WriteLine(j); } } class Program { static void Main(string[] args) { B obj = new B(); obj.j = 1; obj.i = 8; obj.display(); Console.ReadLine(); } } }

  1. A. 8, 1
  2. B. 8
  3. C. 1
  4. D. 1, 8
Report Error

If a class inheriting an abstract class does not define all of its functions then it is known as?

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

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

  1. A. Class a could not have an instance data
  2. B. Class a is an abstract class
  3. C. Class a fully implements the interface a1
  4. D. None of the mentioned
Report Error

Correct method to define + operator is?

  1. A. public sample operator +(int a, int
  2. B. B. public abstract operator +(int a, int b) C. public static sample operator +(int a, int b) D. public abstract sample operator +(int a, int b)
Report Error

Choose the correct statement among the following which supports the fact that C# does not allow the creation of empty structures?

  1. A. C#.NET supports creation of abstract user-defined data types using structures
  2. B. By having empty structures, it would mean that the new data types have no data associated with, which does not make any sense in C#.NET
  3. C. Basic reason to create structures is the inability to represent real life objects using standard data types offered by the language
  4. D. All of the mentioned
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(1)); } }

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

What will be the output of the following C# code? { struct abc { public int i; } class Program { static void Main(string[] args) { sample a = new sample(); a.i = 10; fun(ref a); Console.WriteLine(a.i); } public static voidn fun(ref sample x) { x.i = 20; Console.WriteLine(x.i); } } }

  1. A. 10 10
  2. B. 20 10
  3. C. 10 20
  4. D. 20 20
Report Error

Which of the following statements correctly define about the implementation of interface?

  1. A. The calls to implementation of interface methods are routed through a method table
  2. B. A class which implements an interface can explicitly implement members of that interface
  3. C. One interface can be implemented in another interface
  4. D. None of the mentioned
Report Error

What will be the Correct statement of the following C# code? public class maths { public int x; public virtual void a() { } } public class subject : maths { new public void a() { } }

  1. A. The subject class version of a() method gets called using sample class reference which holds subject class object
  2. B. subject class hides a() method of base class
  3. C. The code replaces the subject class version of a() with its math class version
  4. D. None of the mentioned
Report Error

Select wrong statement about destructor in C#?

  1. A. A class can have one destructor only
  2. B. Destructors cannot be inherited or overloaded
  3. C. Destructors can have modifiers or parameters
  4. D. All of the mentioned
Report Error

When does a structure variable get destroyed?

  1. A. When no reference refers to it, it will get garbage collected
  2. B. Depends on whether it is created using new or without new operator
  3. C. As variable goes out of the scope
  4. D. Depends on either we free its memory using free() or delete()
Report Error

What will be the output of the following C# code? static void Main(string[] args) { m(); Console.ReadLine(); } static void m() { Console.WriteLine("HI"); m(); }

  1. A. HI HI HI
  2. B. HI
  3. C. Stack overflow exception
  4. D. Compile time error
Report Error