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.

Can the method add() be overloaded in the following ways in C#? public int add() { } public float add(){ }

  1. A. True
  2. B. False
Report Error

What will be the output of the following C# code? public static void Main(string[] args) { p(); void p() { Console.WriteLine("hi"); } }

  1. A. Compile time error
  2. B. hi
  3. C. hi infinite times
  4. D. None of the mentioned
Report Error

Which keyword is used for correct implementation of an interface in C#.NET?

  1. A. interface
  2. B. Interface
  3. C. intf
  4. D. Intf
Report Error

What is the return type of constructors?

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

The following C# code is run on single level of inheritance. What will be the Correct statement in the following C# code? class sample { int i = 10; int j = 20; public void display() { Console.WriteLine("base method "); } } class sample1 : sample { public int s = 30; } class Program { static void Main(string[] args) { sample1 obj = new sample1(); Console.WriteLine("{0}, {1}, {2}", obj.i, obj.j, obj.s); obj.display(); Console.ReadLine(); } }

  1. A. 10, 20, 30 base method
  2. B. 10, 20, 0
  3. C. compile time error
  4. D. base method
Report Error

Select the sequence of execution of function f1(), f2() & f3() in C# .NET CODE? class base { public void f1() {} public virtual void f2() {} public virtual void f3() {} } class derived :base { new public void f1() {} public override void f2() {} public new void f3() {} } class Program { static void Main(string[] args) { baseclass b = new derived(); b.f1 (); b.f2 (); b.f3 (); } }

  1. A. f1() of derived class get executed f2() of derived class get executed f3() of base class get executed
  2. B. f1() of base class get executed f2() of derived class get executed f3() of base class get executed
  3. C. f1() of base class get executed f2() of derived class get executed f3() of derived class get executed
  4. D. f1() of derived class get executed f2() of base class get executed f3() of base class get executed
Report Error

Correct way of declaration of object of the following class is? class name

  1. A. name n = new name()
  2. B. n = name()
  3. C. name n = name()
  4. D. n = new name()
Report Error

Wrong statement about inheritance in C# .NET?

  1. A. In inheritance chain, object construction begins from base class towards derived class
  2. B. Inheritance cannot extend base class functionality
  3. C. A derived class object contains all base class data
  4. D. All of the mentioned
Report Error

What will be the output of the following C# code? class box { public int volume; int width; int height; int length; public box ( int w, int h, int l) { this.width = w; this.height = h; this.length = l; } ~ box() { volume = this.width * this.length * this.height; console.writeline(volume); } } class Program { public static void Main(string[] args) { box b = new box(4, 5, 9); Console.ReadLine(); } }

  1. A. 0
  2. B. Code executes successfully but prints nothing
  3. C. Compile time error
  4. D. 180
Report Error

The modifier used to hide the base class methods is?

  1. A. Virtual
  2. B. New
  3. C. Override
  4. D. Sealed
Report Error

Select correct differences between '=' and '==' in C#.

  1. A. '==' operator is used to assign values from one variable to another variable ''=' operator is used to compare value between two variables
  2. B. '=' operator is used to assign values from one variable to another variable '==' operator is used to compare value between two variables
  3. C. No difference between both operators
  4. D. None of the mentioned
Report Error

What will be the output of the following C# code? interface calc { void cal(int i); } class displayA :calc { public int x; public void cal(int i) { x = i * i; } } class displayB :calc { public int x; public void cal(int i) { x = i / i; } } class Program { public static void Main(string[] args) { displayA arr1 = new displayA(); displayB arr2 = new displayB(); arr1.x = 0; arr2.x = 0; arr1.cal(2); arr2.cal(2); Console.WriteLine(arr1.x + " " + arr2.x); Console.ReadLine(); } }

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