Commerce

Classes 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.

Access specifiers which can be used for an interface are?

  1. A. Public
  2. B. Protected
  3. C. Private
  4. D. All of the mentioned
Report Error

What will be the output of the following C# code? class A { public int i; protected int j; } class B : A { public int j; public void display() { base.j = 3; Console.WriteLine(i + " " + j); } } class Program { static void Main(string[] args) { B obj = new B(); obj.i = 1; obj.j = 2; obj.display(); Console.ReadLine(); } }

  1. A. 2 1
  2. B. 1 0
  3. C. 0 2
  4. D. 1 2
Report Error

What is the return type of destructor?

  1. A. int
  2. B. void
  3. C. float
  4. D. none of the mentioned
Report Error

Wrong statement about enum used in C#.NET is?

  1. A. An enum can be declared inside a class
  2. B. An object cannot be assigned to an enum variable
  3. C. An enum can be declared outside a class
  4. D. An enum can have Single and Double values
Report Error

The process of defining a method in a subclass having same name & type signature as a method in its superclass is known as?

  1. A. Method overloading
  2. B. Method overriding
  3. C. Method hiding
  4. D. None of the mentioned
Report Error

What will be the Correct statement in the following C# code? class baseclass { int a; public baseclass(int a1) { a = a1; console.writeline(" a "); } class derivedclass : baseclass { public derivedclass (int a1) : base(a1) { console.writeline(" b "); } } class program { static void main(string[] args) { derivedclass d = new derivedclass(20); } } }

  1. A. Compile time error
  2. B. b a
  3. C. a b
  4. D. The program will work correctly if we replace base(a1) with base.baseclass(a1)
Report Error

What will be the output of the following C# code? static void Main(string[] args) { int i = 10; double d = 35.78; fun(i); fun(d); Console.ReadLine(); } static void fun(double d) { Console.WriteLine(d); }

  1. A. 35.78 10
  2. B. 10 35
  3. C. 10 35.78
  4. D. None of the mentioned
Report Error

The data members of a class by default are?

  1. A. protected, public
  2. B. private, public
  3. C. private
  4. D. public
Report Error

Correct way to overload +operator?

  1. A. public sample operator + (sample a, sample
  2. B. B. public abstract operator + (sample a,sample b) C. public static sample operator + (sample a, sample b) D. all of the mentioned
Report Error

Number of constructors a class can define is?

  1. A. 1
  2. B. 2
  3. C. Any number
  4. D. None of the mentioned
Report Error

What will be the output of the following C# code? static void Main(string[] args) { int a = 5; int s = 0, c = 0; Mul (a, ref s, ref c); Console.WriteLine(s + "t " +c); Console.ReadLine(); } static void Mul (int x, ref int ss, ref int cc) { ss = x * x; cc = x * x * x; }

  1. A. 125 25
  2. B. 25 125
  3. C. Compile time error
  4. D. 0 0
Report Error

If no access modifier for a class is specified, then class accessibility is defined as?

  1. A. public
  2. B. protected
  3. C. private
  4. D. internal
Report Error