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.
A type of class which does not have its own objects but acts as a base class for its subclass is known as?
- A. Static class
- B. Sealed class
- C. Abstract class
- D. None of the mentioned
Correct Answer: C
Choose the wrong statement about structures in C#.NET?
- A. Structures can be declared within a procedure
- B. Structures can implement an interface but they cannot inherit from another structure
- C. Structure members cannot be declared as protected
- D. A structure cannot be empty
Correct Answer: A
In Inheritance concept, which of the following members of base class are accessible to derived class members?
- A. static
- B. protected
- C. private
- D. shared
Correct Answer: B
What will be the output of the following C# code? class maths { public int fun(int ii) { return(ii > 0 ? ii :ii * -1); } public long fun(long ll) { return(ll > 0 ? ll :ll * -1); } public double fun( double dd) { return(dd > 0 ? dd :dd * -1); } } class Program { static void Main(string[] args) { maths obj = new maths(); int i = -25; int j ; long l = -100000l ; long m; double d = -12.34; double e; j = obj.fun(i); m = obj.fun(l); e = obj.fun(d); Console.WriteLine(j + " " + m + " " + e); Console.ReadLine(); } }
- A. 1 1 1
- B. 0 0 0
- C. 25 100000 12.34
- D. -25 -100000 -12.34
Correct Answer: C
What will be the output of the following C# code? static void Main(string[] args) { int y = 3; y++; if (y <= 5) { Console.WriteLine("hi"); Main(args); } Console.ReadLine(); }
- A. hi hi
- B. hi
- C. Stack overflow exception
- D. None of the mentioned
Correct Answer: C
What will be the output of the following C# code? enum letters { a, b, c } letters l; l = letters.a; Console.writeline(l);
- A. -1
- B. 0
- C. a
- D. letters.a
Correct Answer: C
What will be the output of the following C# code? static void Main(string[] args) { int []a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; func(ref a); Console.ReadLine(); } static void func(ref int[] x) { Console.WriteLine(" numbers are:"); for (int i = 0; i < x.Length; i++) { if (x[i] % 2 == 0) { x[i] = x[i] + 1; Console.WriteLine(x[i]); } } }
- A. numbers are : 2 4 6 8 10
- B. numbers are : 3 5 7 9 11
- C. numbers are : 2 3 4 5 6
- D. none of the mentioned
Correct Answer: B
Which operator among the following signifies the destructor operator?
- A. ::
- B. :
- C. ~
- D. &
Correct Answer: C
Which of these will happen if the recursive method does not have a base case?
- A. Infinite loop condition occurrence
- B. System gets hanged
- C. After 10000 executions program will be automatically stopped
- D. None of the mentioned
Correct Answer: A
What will be the output of the following C# code? static void Main(string[] args) { int a = 10 , b = 20; Console.WriteLine("Result before swap is: "+ a +" "+b); swap(ref a, ref b); Console.ReadLine(); } static void swap(ref int i, ref int j) { int t; t = i; i = j; j = t; Console.WriteLine("Result after swap is:"+ i +" "+j); }
- A. Result before swap is: 20 10 Result after swap is: 20 10
- B. Result before swap is: 10 20 Result after swap is:20 10
- C. Result before swap is: 10 20 Result after swap is:10 20
- D. Result before swap is: 20 10 Result after swap is:10 20
Correct Answer: B
What will be the output of the following C# code? class maths { public static void fun1() { Console.WriteLine("method 1 :"); } public void fun2() { fun1(); Console.WriteLine("method 2 :"); } public void fun2(int k) { Console.WriteLine(k); fun2(); } } class Program { static void Main(string[] args) { maths obj = new maths(); maths.fun1(); obj.fun2(20); Console.ReadLine(); } }
- A. method 1: method 2: 20 method 1:
- B. method 2: 20 method 1: method 1:
- C. method 1: 0 method 2: method 2:
- D. method 1: 20 method 1: method 2:
Correct Answer: D
Which of the following cannot be used to declare a class as a virtual?
- A. Methods
- B. Properties
- C. Events
- D. Fields
Correct Answer: D