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.
When we call a constructor method among different given constructors. We match the suitable constructor by matching the name of constructor first, then the number and then the type of parameters to decide which constructor is to be overloaded. The process is also known as?
- A. Method overriding
- B. Inheritance
- C. Polymorphism
- D. Encapsulation
Correct Answer: C
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(4)*(3)); } }
- A. 64
- B. 60
- C. 72
- D. 84
Correct Answer: C
Select the correct statement among the given statements?
- A. One class could implement only one interface
- B. Properties could be declared inside an interface
- C. Interfaces cannot be inherited
- D. None of the mentioned
Correct Answer: B
Correct statement about constructor overloading in C# is?
- A. Overloaded constructors have the same name as the class
- B. Overloaded constructors cannot use optional arguments
- C. Overloaded constructors can have different type of number of arguments as well as differ in number of arguments
- D. All of the mentioned
Correct Answer: C
The modifier used to define a class which does not have objects of its own but acts as a base class for its subclass is?
- A. Sealed
- B. Static
- C. New
- D. Abstract
Correct Answer: D
What will be the output of the following C# code? class sample { int i; double k; public sample (int ii, double kk) { i = ii; k = kk; double j = (i) + (k); Console.WriteLine(j); } ~sample() { double j = i - k; Console.WriteLine(j); } } class Program { static void Main(string[] args) { sample s = new sample(8, 2.5); Console.ReadLine(); } }
- A. 0 0
- B. 10.5 0
- C. Compile time error
- D. 10.5 5.5
Correct Answer: D
Which of these operators must be used to inherit a class?
- A. :
- B. &
- C. ::
- D. extends
Correct Answer: A
Select the wrong statement about 'ref' keyword in C#?
- A. References can be called recursively
- B. The 'ref' keyword causes arguments to be passed by reference
- C. When 'ref' are used, any changes made to parameters in method will be reflected in variable when control is passed back to calling method
- D. All of the mentioned
Correct Answer: A
A class member declared protected becomes member of subclass of which type?
- A. public member
- B. private member
- C. protected member
- D. static member
Correct Answer: D
The number of levels of inheritance are?
- A. 5
- B. 4
- C. 3
- D. 2
Correct Answer: B
What is the vector in operator overloading?
- A. class
- B. method()
- C. data type
- D. none of the mentioned
Correct Answer: C
What will be the output of the following C# code? class maths { public int fun1(int k) { k = 20; return k; } public Single fun1(float t) { t = 3.4f; return t; } } class Program { static void Main(string[] args) { maths obj = new maths(); int i; i = obj.fun1(30); Console.WriteLine(i); Single j; j = obj.fun1(2.5f); Console.WriteLine(j); Console.ReadLine(); } }
- A. 30 2.5f
- B. 2.5f 30
- C. 20 2.5f
- D. 20 3.4f
Correct Answer: D