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? interface i1 { void f1(); } interface i2 :i1 { void f2(); } public class maths :i2 { public void f2() { Console.WriteLine("fun2"); } public void f1() { Console.WriteLine("fun1"); } } class Program { static Void Main() { maths m = new maths(); m.f1(); m.f2(); } }

  1. A. fun2
  2. B. fun1
  3. C. fun1 fun2
  4. D. fun2 fun1
Report Error

What will be the Correct statement in the following C# code? interface abc { String FirstName { get; set; } String LastName { get; set; } void print(); void stock(); int fun(); }

  1. A. Functions should be declared inside an interface
  2. B. It is workable code
  3. C. Properties cannot be declared inside an interface
  4. D. None of the mentioned
Report Error

What does the following C# code signify? class a { } class b : a { variable declaration; method declaration; }

  1. A. Declaration of a base class
  2. B. Declaration of a subclass
  3. C. Declaration of base class & subclass and how subclass inherits the base class
  4. D. None of the mentioned
Report Error

Which of the following is the correct way of implementing an interface addition by class maths?

  1. A. class maths : addition {}
  2. B. class maths implements addition {}
  3. C. class maths imports addition {}
  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 = 6,Y = 2; X *= X / Y; Console.WriteLine(X); Console.ReadLine(); }

  1. A. 12
  2. B. 6
  3. C. 18
  4. D. Compile time error
Report Error

What will be the output of the following C# code? enum days:int { sunday = -3, monday, tuesday } Console.WriteLine((int)days.sunday); Console.WriteLine((int)days.monday); Console.WriteLine((int)days.tuesday);

  1. A. -3 0 1
  2. B. 0 1 2
  3. C. -3 -2 -1
  4. D. sunday monday tuesday
Report Error

What will be the output of the following C# code? class maths { static maths() { int s = 8; Console.WriteLine(s); } public maths(int f) { int h = 10; Console.WriteLine(h); } } class Program { static void Main(string[] args) { maths p = new maths(0); Console.ReadLine(); } }

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

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

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

Select the class visibility modifiers among the following:

  1. A. Private, protected, public, internal
  2. B. Private, protected, public, internal, protected internal
  3. C. Private, protected, public
  4. D. All of the mentioned
Report Error

Which of these can be used to fully abstract a class from its implementation?

  1. A. Objects
  2. B. Packages
  3. C. Interfaces
  4. D. None of the Mentioned
Report Error

Which statements among following are correct?

  1. A. We can derive a class from a base class even if source code of base class not available
  2. B. Multiple inheritance is different from multiple levels of inheritance
  3. C. It is legal to make objects of one class as members of another class
  4. D. All of the mentioned
Report Error

Which return statement correctly returns the output?

  1. A. public int cube(int x) { return (x + x); }
  2. B. public int cube(int x) return (x + x)
  3. C. public int cube(int x) { return x + x; }
  4. D. None of the mentioned
Report Error