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 correct statement in the following C# code? struct book { private String name; private int pages; private Single price; } book b = new book();

  1. A. New structure can be inherited from struct book
  2. B. When the program terminates, variable b will get garbage collected
  3. C. The structure variable 'b' will be created on the stack
  4. D. None of the above
Report Error

What will be the output of the following C# code? namespace ConsoleApplication4 { abstract class A { public int i ; public int j ; public abstract void display(); } class B: A { public int j = 5; public override void display() { this.j = 3; Console.WriteLine(i + " " + j); } } class Program { static void Main(string[] args) { B obj = new B(); obj.i = 1; obj.display(); Console.ReadLine(); } } }

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

What will be the correct statement in the following C# code? class trial { int i; float d; } struct sample { private int x; private Single y; private trial z; } sample s = new sample();

  1. A. trial object referred by z is created on the stack
  2. B. z is created on the heap
  3. C. Both s and z will be created on the heap
  4. D. s will be created on the stack
Report Error

Which statement correctly defines Interfaces in C#.NET?

  1. A. Interfaces cannot be inherited
  2. B. Interfaces consists of data static in nature and static methods
  3. C. Interfaces consists of only method declaration
  4. D. None of the mentioned
Report Error

Does C#.NET support partial implementation of interfaces?

  1. A. True
  2. B. False
  3. C. Can't Say
  4. D. None of the mentioned
Report Error

What will be the output of the following C# code? 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.i = 1; obj.j = 2; obj.display(); Console.ReadLine(); } }

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

Choose the correct statement about structures as to why they are defined as value types but not reference types?

  1. A. Since space required for structure variables is allocated on stack which is a form of memory that is automatically available when a variable to be used is in scope
  2. B. Structures generally are used to represent user defined data types that consists of small amount of data in them. Hence using stack for declaration of such variables is not a problem
  3. C. All of the mentioned
  4. D. None of the mentioned
Report Error

What will be the Correct statement in the following C# code? class sample { protected int index; public sample() { index = 0; } } class sample 1: sample { public void add() { index += 1; } } class Program { static void Main(string[] args) { sample 1 z = new sample 1(); z . add(); } }

  1. A. Index should be declared as protected if it is to become available in inheritance chain
  2. B. Constructor of sample class does not get inherited in sample 1 class
  3. C. During constructing an object referred to by z, Firstly constructor of sample class will be called followed by constructor of sample 1 class
  4. D. All of the mentioned
Report Error

What will be the output of the following C# code? using System; public class BaseClass { public BaseClass() { Console.WriteLine("I am a base class"); } } public class ChildClass : BaseClass { public ChildClass() { Console.WriteLine ("I am a child class"); } static void Main() { ChildClass CC = new ChildClass(); } }

  1. A. I am a base class I am a child class
  2. B. I am a child class I am a base class
  3. C. Compile time error
  4. D. None of the mentioned
Report Error

Choose the statements which makes interface different from classes?

  1. A. Unlike classes, interfaces consists of only declaration but not implementation
  2. B. Interfaces cannot be used directly like classes to create new objects
  3. C. Interfaces consists of declaration of methods, properties events and type definitions
  4. D. All of the mentioned
Report Error

Operator used to free the memory when memory is allocated?

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

What will be the output of the following C# code? class box { public int volume; int width; int height; int length; public box ( int w, int h, int l) { width = w; height = h; length = l; } public ~box() { volume = width * length * height; } } class Program { static void Main(string[] args) { box b = new box(4, 5, 9); Console.WriteLine(b.volume); Console.ReadLine(); } }

  1. A. 0
  2. B. 180
  3. C. Compile time error
  4. D. None of the mentioned
Report Error