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.
The method called by clients of a class to explicitly release any resources like network, connection, open files etc. When the object is no longer required?
- A. Finalize()
- B. End()
- C. Dispose()
- D. Close()
Correct Answer: C
Select the correct statement from the following?
- A. Static methods can be a virtual method
- B. Abstract methods can be a virtual method
- C. When overriding a method, the names and type signatures of the override method must be the same as the virtual method that is being overridden
- D. We can override virtual as well as nonvirtual methods
Correct Answer: C
What will be the output of the following C# code? class maths { public int fun(int k, int y) { return k + y; } public int fun1(int t, float z) { return (t+(int)z); } } class Program { static void Main(string[] args) { maths obj = new maths(); int i; int b = 90; int c = 100; int d = 12; float l = 14.78f; i = obj.fun(b, c); Console.WriteLine(i); int j = (obj.fun1(d, l)); Console.WriteLine(j); Console.ReadLine(); } }
- A. 190, 26.78f
- B. 0, 26.78f
- C. 190, 26
- D. 190, 0
Correct Answer: C
Correct way to define object of sample class in which C# code will work correctly is: class abc { int i; float k; public abc(int ii, float kk) { i = ii; k = kk; } }
- A. abc s1 = new abc(1)
- B. abc s1 = new abc()
- C. abc s2 = new abc(1.4f)
- D. abc s2 = new abc(1, 1.4f)
Correct Answer: D
What will be the output of the following C# code? static void Main(string[] args) { int a = 5; fun1 (ref a); Console.WriteLine(a); Console.ReadLine(); } static void fun1(ref int a) { a = a * a; }
- A. 5
- B. 0
- C. 20
- D. 25
Correct Answer: D
Choose the correct statement among the below mentioned statements.
- A. Forgetting to declare an operator method as public
- B. Forgetting to declare an operator method as static
- C. Forgetting to return a bool type value while overloading a relational operator
- D. All of the mentioned
Correct Answer: D
What will be the output of the following C# code? static void Main(string[] args) { int[] arr = new int[] {1, 2, 3, 4, 5}; fun1(ref arr); Console.ReadLine(); } static void fun1(ref int[] array) { for (int i = 0; i < array.Length; i++) { array[i] = array[i] + 5; Console.WriteLine(array[i] + " "); } }
- A. 6 7 8 9 10
- B. 15 17 8 8 20
- C. 15 17 8 29 20
- D. Syntax error while passing reference of array variable
Correct Answer: A
Which of the following modifiers is used when an abstract method is redefined by a derived class?
- A. Overloads
- B. Override
- C. Base
- D. Virtual
Correct Answer: B
Correct statement about constructors in C#.NET is?
- A. Constructors can be overloaded
- B. Constructors are never called explicitly
- C. Constructors have same name as name of the class
- D. All of the mentioned
Correct Answer: D
What will be the output of the following C# code? class recursion { int fact(int n) { int result; if (n == 1) return 1; result = fact(n - 1) * n; return result; } } class Program { public static void main(String args[]) { recursion obj = new recursion() ; Console.WriteLine(obj.fact(4)); } }
- A. 24
- B. 30
- C. 120
- D. 144
Correct Answer: A
Wrong statement about run time polymorphism is?
- A. The overridden base method should be virtual, abstract or override
- B. An abstract method is implicitly a virtual method
- C. An abstract inherited property cannot be overridden in a derived class
- D. Both override method and virtual method must have same access level modifier
Correct Answer: C
Which method has the same name as that of its class?
- A. delete
- B. class
- C. constructor
- D. none of the mentioned
Correct Answer: C