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 abc { public static void a() { console.writeline("first method"); } public void b() { a(); console.writeline("second method"); } public void b(int i) { console.writeline(i); b(); } } class program { static void main() { abc k = new abc(); abc.a(); k.b(20); } }
- A. second method 20 second method first method
- B. first method 20 first method second method
- C. first method 20
- D. second method 20 first method
Correct Answer: B
What will be the output of the following C# code? class sample { public int i; void display() { Console.WriteLine(i); } } class sample1 : sample { public int j; public void display() { Console.WriteLine(j); } } class Program { static void Main(string[] args) { sample1 obj = new sample1(); obj.i = 1; obj.j = 2; obj.display(); Console.ReadLine(); } }
- A. 1
- B. 3
- C. 2
- D. Compile Time error
Correct Answer: C
What will be the output of the following C# code? class a { public void fun() { Console.WriteLine("base method"); } } class b: a { public new void fun() { Console.WriteLine(" derived method "); } } class Program { static void Main(string[] args) { b k = new b(); k.fun(); Console.ReadLine(); } }
- A. Base method
- B. Derived method
- C. Code runs successfully prints nothing
- D. Compile time error
Correct Answer: B
Which among the following differentiates enum in C#.NET from enum in C language?
- A. C is strictly a typed language, C#.NET also is a strictly typed language
- B. In C, language variables of enum types can be used interchangeably with integers using type casts while enum variables cannot be used as a normal integers in C#.NET
- C. None of the mentioned
- D. All of the mentioned
Correct Answer: B
What will be the output of the following C# code snippet? class maths { public int fact(int n) { int result; if (n == 2) return 1; result = fact(n - 1) * n; return result; } } class Program { static void Main(string[] args) { maths obj = new maths(); Console.WriteLine(obj.fact(4)); Console.ReadLine(); } }
- A. 24
- B. 0
- C. 12
- D. 1
Correct Answer: C
Which form of inheritance is not supported directly by C# .NET?
- A. Multiple inheritance
- B. Multilevel inheritance
- C. Single inheritance
- D. Hierarchical inheritance
Correct Answer: A
Which of the following statements are correct in nature?
- A. The conditional logical operators cannot be overloaded
- B. The array indexing operator can be overloaded
- C. A public or nested public preference type does not overload the equality operator
- D. None of the mentioned
Correct Answer: A
What will be the Correct statement in the following C# code? interface a1 { void f1(); int f2(); } class a :a1 { void f1() { } int a1.f2() { } }
- A. class a is an abstract class
- B. A method table would not be created for class a
- C. The definition of f1() in class a should be void a1.f1()
- D. None of the mentioned
Correct Answer: C
What will be the output of the following C# code? class maths { public int x; public double y; public int add(int a, int b) { x = a + b; return x; } public int add(double c, double d) { y = c + d; return (int)y; } public maths() { this.x = 0; this.y = 0; } } class Program { static void Main(string[] args) { maths obj = new maths(); int a = 4; double b = 3.5; obj.add(a, a); obj.add(b, b); Console.WriteLine(obj.x + " " + obj.y); Console.ReadLine(); } }
- A. 4, 3.5
- B. 8, 0
- C. 7.5, 8
- D. 8, 7
Correct Answer: D
Select the wrong statements among the following?
- A. A structure can contain properties
- B. A structure can contain constructors
- C. A structure can contain protected data members
- D. A structure can contain constants
Correct Answer: C
What will be the output of the following C# code? class sample { public sample() { Console.WriteLine("THIS IS BASE CLASS constructor"); } } public class sample1 : sample { } class Program { static void Main(string[] args) { sample1 obj = new sample1(); Console.ReadLine(); } }
- A. Code executes successfully prints nothing
- B. This is base class constructor
- C. Compile time error
- D. None of the mentioned
Correct Answer: C
What will be the output of the following C# code? enum per { a, b, c, d, } per.a = 10; Console.writeline(per.b);
- A. 11
- B. 1
- C. 2
- D. compile time error
Correct Answer: D