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.

What will be the output of the following C# code? enum colors { red, black, pink } colors s = colors.black; type t; t = c.GetType(); string[] str; str = Enum.GetNames(t); Console.WriteLine(str[0]);

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

What will be the output of the following C# code? class maths { public maths() { Console.WriteLine("constructor 1 :"); } public maths(int x) { int p = 2; int u; u = p + x; Console.WriteLine("constructor 2: " +u); } } class Program { static void Main(string[] args) { maths k = new maths(4); maths t = new maths(); Console.ReadLine(); } }

  1. A. constructor 1: constructor 2: 6
  2. B. constructor 2: 6 constructor 2: 6
  3. C. constructor 2: 6 constructor 1:
  4. D. none of the mentioned
Report Error

Arrange the following overloaded operators in increasing order of precedence? %, <<, &, /, +

  1. A. '%' < '<<' < '+' < '-' < '&' < '/'
  2. B. '<<' < '&' < '%' < '-' < '/' < '+'
  3. C. '&' < '-' <'%' < '<<' < '/' < '+'
  4. D. '/' < '-' < '%' < '+' < '<<' < '&'
Report Error

What will be the output of the following C# code? interface i1 { void fun(); } interface i2 { void fun(); } public class maths :i1, i2 { void i1.fun() { Console.WriteLine("i1.fun"); } void i2.fun() { Console.WriteLine("i2.fun"); } } class Program { static void Main(string[] args) { Sample obj = new Sample(); i1 i = (i1) obj; i.fun(); i2 ii = (i2) obj; ii.fun(); } }

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

Given class sample is inherited by class sample 1. Which are the correct statements about construction of object of class sample?

  1. A. While creating the object firstly the constructor of class sample will be called followed by constructor of class sample 1
  2. B. The constructor of only sample class will be called
  3. C. While creating the object firstly constructor of class sample 1 will be called followed by constructor of class sample
  4. D. The order of calling constructors depend on whether constructors in class sample and sample 1 are private or public
Report Error

What is the most specified using class declaration?

  1. A. type
  2. B. scope
  3. C. type & scope
  4. D. none of the mentioned
Report Error

What will be the output of the following C# code? static void Main(string[] args) { int x = 8; int b = 16; int C = 64; x /= b /= C /= x; Console.WriteLine(x + " " + b+ " " +C); Console.ReadLine(); }

  1. A. 8 2 4
  2. B. 2 4 8
  3. C. 4 2 8
  4. D. Compile time error
Report Error

Which C# statement should be added in function a() of class y to get output "i love csharp"? class x { public void a() { console.write("bye"); } } class y : x { public void a() { /* add statement here */ console.writeline(" i love csharp "); } } class program { static void main(string[] args) { y obj = new obj(); obj.a(); } }

  1. A. x.a()
  2. B. a()
  3. C. base.a()
  4. D. x::a()
Report Error

The capability of an object in Csharp to take number of different forms and hence display behaviour as according is known as . . . . . . . .

  1. A. Encapsulation
  2. B. Polymorphism
  3. C. Abstraction
  4. D. None of the mentioned
Report Error

What will be the output of the following C# code? class z { public int X; public int Y; public const int c1 = 5; public const int c2 = c1 * 25; public void set(int a, int b) { X = a; Y = b; } } class Program { static void Main(string[] args) { z s = new z(); s.set(10, 20); Console.WriteLine(s.X + " " + s.Y); Console.WriteLine(z.c1 + " " + z.c2); Console.ReadLine(); } }

  1. A. 10 20 5 25
  2. B. 20 10 25 5
  3. C. 10 20 5 125
  4. D. 20 10 125 5
Report Error

Which procedure among the following should be used to implement a 'Has a' or a 'Kind of' relationship between two entities?

  1. A. Polymorphism
  2. B. Inheritance
  3. C. Templates
  4. D. All of the mentioned
Report Error

What will be the output of the following C# code? static void Main(string[] args) { int x = 8; int b = 16; int C = 64; x /= b /= C; Console.WriteLine(x + " " + b+ " " +C); Console.ReadLine(); }

  1. A. 8 2 32
  2. B. 32 4 8
  3. C. 32 2 8
  4. D. Compile time error
Report Error