CommerceClasses 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();
- A. New structure can be inherited from struct book
- B. When the program terminates, variable b will get garbage collected
- C. The structure variable 'b' will be created on the stack
- D. None of the above
Correct Answer: C
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(); } } }
- A. 1, 5
- B. 0, 5
- C. 1, 0
- D. 1, 3
Correct Answer: D
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();
- A. trial object referred by z is created on the stack
- B. z is created on the heap
- C. Both s and z will be created on the heap
- D. s will be created on the stack
Correct Answer: D
Which statement correctly defines Interfaces in C#.NET?
- A. Interfaces cannot be inherited
- B. Interfaces consists of data static in nature and static methods
- C. Interfaces consists of only method declaration
- D. None of the mentioned
Correct Answer: D
Does C#.NET support partial implementation of interfaces?
- A. True
- B. False
- C. Can't Say
- D. None of the mentioned
Correct Answer: B
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(); } }
- A. 0
- B. 2
- C. 1
- D. Compile time error
Correct Answer: B
Choose the correct statement about structures as to why they are defined as value types but not reference types?
- 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
- 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
- C. All of the mentioned
- D. None of the mentioned
Correct Answer: C
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(); } }
- A. Index should be declared as protected if it is to become available in inheritance chain
- B. Constructor of sample class does not get inherited in sample 1 class
- C. During constructing an object referred to by z, Firstly constructor of sample class will be called followed by constructor of sample 1 class
- D. All of the mentioned
Correct Answer: D
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(); } }
- A. I am a base class I am a child class
- B. I am a child class I am a base class
- C. Compile time error
- D. None of the mentioned
Correct Answer: A
Choose the statements which makes interface different from classes?
- A. Unlike classes, interfaces consists of only declaration but not implementation
- B. Interfaces cannot be used directly like classes to create new objects
- C. Interfaces consists of declaration of methods, properties events and type definitions
- D. All of the mentioned
Correct Answer: D
Operator used to free the memory when memory is allocated?
- A. new
- B. free
- C. delete
- D. none of the mentioned
Correct Answer: C
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(); } }
- A. 0
- B. 180
- C. Compile time error
- D. None of the mentioned
Correct Answer: C