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 output of the following C# code? class test { public void print() { Console.WriteLine("Csharp:"); } } class Program { static void Main(string[] args) { test t; t.print(); Console.ReadLine(); } }
- A. Code runs successfully prints nothing
- B. Code runs and prints "Csharp"
- C. Syntax error as t is unassigned variable which is never used
- D. None of the mentioned
Correct Answer: C
Which keyword is used to refer baseclass constructor to subclass constructor?
- A. This
- B. Static
- C. Base
- D. Extend
Correct Answer: C
What will be the output of the following C# code? class maths { int i; public maths(int ii) { ii = 12; int j = 12; int r = ii * j; Console.WriteLine(r); } } class maths1 : maths { public maths1(int u) :base(u) { u = 13; int h = 13; Console.WriteLine(u + h); } } class maths2 : maths1 { public maths2(int k) :base(k) { k = 24; int o = 6 ; Console.WriteLine(k /o); } } class Program { static void Main(string[] args) { maths2 t = new maths2(10); Console.ReadLine(); } }
- A. 4, 26, 144
- B. 26, 4, 144
- C. 144, 26, 4
- D. 0, 0, 0
Correct Answer: C
What is Recursion in CSharp defined as?
- A. Recursion is another form of class
- B. Recursion is another process of defining a method that calls other methods repeatedly
- C. Recursion is a process of defining a method that calls itself repeatedly
- D. Recursion is a process of defining a method that calls other methods which in turn calls this method
Correct Answer: C
Calculate the number of bytes a structure variable s occupies in the memory if it is defined as follows. class abc { int i; Decimal d; } struct sample { private int x; private Single y; private trial z; } sample s = new sample();
- A. 24 bytes
- B. 8 bytes
- C. 16 bytes
- D. 12 bytes
Correct Answer: D
To override a method in the subclass, the base class method should be defined as?
- A. Virtual
- B. Abstract
- C. Override
- D. All of the mentioned
Correct Answer: D
"A mechanism that binds together code and data in manipulates, and keeps both safe from outside interference and misuse. In short it isolates a particular code and data from all other codes and data. A well-defined interface controls access to that particular code and data."
- A. Abstraction
- B. Polymorphism
- C. Inheritance
- D. Encapsulation
Correct Answer: D
What will be the output of the following C# code? class maths { int i; public maths(int x) { i = x; Console.WriteLine(" hello: "); } } class maths1 : maths { public maths1(int x) :base(x) { Console.WriteLine("bye"); } } class Program { static void Main(string[] args) { maths1 k = new maths1(12); Console.ReadLine(); } }
- A. hello bye
- B. 12 hello
- C. bye 12
- D. Compile time error
Correct Answer: A
Which reference modifier is used to define reference variable?
- A. &
- B. ref
- C. #
Correct Answer: B
What will be the output of the following C# code? class overload { public int x; int y; public int add(int a) { x = a + 1; return x; } public int add(int a, int b) { x = a + 2; return x; } } class Program { static void Main(string[] args) { overload obj = new overload(); overload obj1 = new overload(); int a = 0; obj.add(6); obj1.add(6, 2); Console.WriteLine(obj.x); Console.WriteLine(obj1.x); Console.ReadLine(); } }
- A. 8 8
- B. 0 2
- C. 8 10
- D. 7 8
Correct Answer: D
Choose the correct statements among the following:
- A. An abstract method does not have implementation
- B. An abstract method can take either static or virtual modifiers
- C. An abstract method can be declared only in abstract class
- D. All of the mentioned
Correct Answer: D
A class consists of two interfaces with each interface consisting of three methods. The class had no instance data. Which of the following indicates the correct size of object created from this class?
- A. 12 bytes
- B. 16 bytes
- C. 0 bytes
- D. 24 bytes
Correct Answer: D