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? class maths { int i; public maths(int ii) { ii = -25; int g; g = ii > 0 ? ii : ii * -1; Console.WriteLine(g); } } class maths1 :maths { public maths1(int ll) :base(ll) { ll = -1000; Console.WriteLine((ll > 0 ? ll : ll * -1)); } } class Program { static void Main(string[] args) { maths1 p = new maths1(6); Console.ReadLine(); } }

  1. A. -25 -1000
  2. B. -1000 -25
  3. C. 25 1000
  4. D. None of the mentioned
Report Error

What will be the output of the following C# code? enum color:int { red, green, blue = 5, cyan, pink = 10, brown } console.writeline((int)color.green); console.writeline((int)color.brown);

  1. A. 2 10
  2. B. 2 11
  3. C. 1 11
  4. D. 1 5
Report Error

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

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

Choose the wrong statement from the given set of statements?

  1. A. All operators in C#.NET cannot be overloaded
  2. B. We can use the new modifier to modify a nested type if the nested type is hiding another type
  3. C. Operator overloading permits the use of symbols to represent computations for a type
  4. D. In case of operator overloading all parameters must be of different type than the class or struct that declares the operators
Report Error

Which statements are correct about operator overloading?

  1. A. Mathematical or physical modeling where we use classes to represent objects such as vectors, matrices, complex-numbers etc
  2. B. Graphical programs where coordinate related objects are used to represent positions on the screen
  3. C. Financial programs where a class represents an amount of money
  4. D. All of the mentioned
Report Error

Name a method which has the same name as that of class and which is used to destroy objects also called automatically when application is finally on process of being getting terminated.

  1. A. Constructor
  2. B. Finalize()
  3. C. Destructor
  4. D. End
Report Error

Which of these is not a correct statement?

  1. A. A recursive method must have a base case
  2. B. Recursion always uses stack
  3. C. Recursion is always managed by C# Runtime environment
  4. D. Recursive methods are faster that programmer written loop to call the function repeatedly using a stack
Report Error

Which is the correct way to create an object of the given class abc?

  1. A. Declaring existing class as sealed
  2. B. Declaring existing class as override
  3. C. Declaring existing class as overloads
  4. D. Declaring existing class as shadows
Report Error

What will be the output of the following C# code? class A { public virtual void display() { Console.WriteLine("A"); } } class B: A { public override void display() { Console.WriteLine(" B "); } } class Program { static void Main(string[] args) { A obj1 = new A(); B obj2 = new B(); A r; r = obj1; r.display(); r = obj2; r.display(); Console.ReadLine(); } }

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

Choose the correct statements about enum used in C#.NET?

  1. A. An enum variable cannot have a private access modifier
  2. B. An enum variable can be defined inside a class or a namespace
  3. C. An enum variable cannot have a protected access modifier
  4. D. An enum variable cannot have a public access modifier
Report Error

What does the following C# code imply? csharp abc; abc = new charp();

  1. A. Object creation on class csharp
  2. B. Create an object of type csharp on heap or on stack depending on the size of object
  3. C. create a reference c on csharp and an object of type csharp on heap
  4. D. create an object of type csharp on stack
Report Error

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

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