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.

How many values does a function return?

  1. A. 0
  2. B. 2
  3. C. 1
  4. D. any number of values
Report Error

Which statements are correct?

  1. A. If a base class consists of a member function fun() and a derived class do not have any function with this name. An object of derived class can access fun()
  2. B. A class D can be derived from class C, which is derived from class B which in turn is derived from class A
  3. C. If a base class and a derived class each include a member function with same name, the member function of the derived class will be called by object of derived class
  4. D. All of the mentioned
Report Error

What will be the output of the following C# expression? int a+= (float) b/= (long)c.

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

What will be the output of the following C# code? class z { public string name1; public string address; public void show() { Console.WriteLine("{0} is in city{1}", name1, " ", address); } } class Program { static void Main(string[] args) { z n = new z(); n.name1 = "harsh"; n.address = "new delhi"; n.show(); Console.ReadLine(); } }

  1. A. Syntax error
  2. B. {0} is in city{1} harsh new delhi
  3. C. harsh is in new delhi
  4. D. Run successfully prints nothing
Report Error

Which keyword is used to declare a base class method while performing overriding of base class methods?

  1. A. this
  2. B. virtual
  3. C. override
  4. D. extend
Report Error

What is the process of defining a method in terms of itself, that is a method that calls itself?

  1. A. Polymorphism
  2. B. Abstraction
  3. C. Encapsulation
  4. D. Recursion
Report Error

Which of the following functionality is facilitated by inheritance mechanism?

  1. A. Use the existing functionality of base class
  2. B. Override the existing functionality of base class
  3. C. Implements new functionality in derived class
  4. D. All of the mentioned
Report Error

Which of these keywords is used to refer to member of base class from a sub class?

  1. A. upper
  2. B. base
  3. C. this
  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 = 4 ,b = 2; x -= b/= x * b; Console.WriteLine(x + " " + b); Console.ReadLine(); }

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

What will be the output of the following C# code? class maths { public int length; public int breadth; public maths(int x, int y) { length = x; breadth = y; Console.WriteLine(x + y); } public maths(double x, int y) { length = (int)x; breadth = y; Console.WriteLine(x * y); } } class Program { static void Main(string[] args) { maths m = new maths(20, 40); maths k = new maths(12.0, 12); Console.ReadLine(); } }

  1. A. 60, 24
  2. B. 60, 0
  3. C. 60, 144
  4. D. 60, 144.0
Report Error

The process of defining two or more methods within the same class that have same name but different parameters list?

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

What will be the output of the following C# code? namespace ConsoleApplication4 { abstract class A { public int i; public abstract void display(); } class B: A { public int j; public int sum; public override void display() { sum = i + j; Console.WriteLine(+i + "n" + +j); Console.WriteLine("sum is:" +sum); } } class Program { static void Main(string[] args) { A obj = new B(); obj.i = 2; B obj1 = new B(); obj1.j = 10; obj.display(); Console.ReadLine(); } } }

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