C# banner

C# Multiple Choice Questions (MCQs) and Answers

Master C# with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of C# concepts. Begin your placement preparation journey now!

Q91

Q91 What is the purpose of a constructor in a class?

A

To initialize the object

B

To destroy the object

C

To clone the object

D

To overload methods

Q92

Q92 Which of the following is a correct way to define a parameterized constructor in C#?

A

public MyClass(int x) { }

B

public MyClass { int x; }

C

public void MyClass(int x) { }

D

public void MyClass { int x; }

Q93

Q93 Which keyword is used to refer to the current instance of the class?

A

self

B

this

C

base

D

current

Q94

Q94 What is the difference between a field and a property in C#?

A

Fields are used to store data, properties are used to encapsulate fields

B

Fields are methods, properties are variables

C

Fields are public, properties are private

D

There is no difference

Q95

Q95 What is the purpose of a destructor in a class?

A

To clean up resources used by the object

B

To initialize the object

C

To overload methods

D

To inherit from another class

Q96

Q96 How do you create an instance of a class named 'Car'?

A

Car myCar = new Car();

B

Car myCar();

C

Car myCar = Car();

D

new Car myCar;

Q97

Q97 How do you define a property in C#?

A

public int MyProperty { get; set; }

B

public int MyProperty { get set; }

C

public int MyProperty { set; }

D

public int MyProperty { get; }

Q98

Q98 How do you define a read-only property in C#?

A

public int MyProperty { get; }

B

public int MyProperty { set; }

C

public readonly int MyProperty { get; set; }

D

public int MyProperty { get; private set; }

Q99

Q99 You get an error 'Constructor not defined'.
What is the likely cause?

A

No constructor is defined in the class

B

The constructor is private

C

The constructor is static

D

The constructor is virtual

Q100

Q100 You encounter a 'null reference exception' when accessing a class member.
What could be the cause?

A

The object is not instantiated

B

The method is not defined

C

The field is private

D

The class is abstract

Q101

Q101 You get a 'field initializer cannot reference' error.
What is the likely cause?

A

Trying to use 'this' keyword in field initializer

B

Field initializer has syntax error

C

Using private field in public property

D

Incorrect use of static keyword

Q102

Q102 What is inheritance in C#?

A

A way to create new classes from existing classes

B

A way to encapsulate data

C

A way to override methods

D

A way to create interfaces

Q103

Q103 Which keyword is used to inherit a base class in C#?

A

base

B

inherit

C

extends

D

:

Q104

Q104 What is polymorphism in C#?

A

The ability to process objects differently based on their data type

B

The ability to inherit from multiple classes

C

The ability to encapsulate data

D

The ability to create new classes

Q105

Q105 What is the purpose of the 'abstract' keyword in C#?

A

To define methods that must be implemented in derived classes

B

To create instances of the class

C

To make the class immutable

D

To define read-only properties

Q106

Q106 Which of the following is true about method overriding in C#?

A

The method in the base class must be marked as virtual

B

The method in the derived class must have the same signature

C

The method in the derived class must be marked as override

D

All of the above

Q107

Q107 How do you define an abstract method in C#?

A

public abstract void MyMethod();

B

public virtual void MyMethod();

C

public override void MyMethod();

D

public void MyMethod();

Q108

Q108 How do you override a method in a derived class in C#?

A

public override void MyMethod() { // code }

B

public virtual void MyMethod() { // code }

C

public void MyMethod() { // code }

D

public new void MyMethod() { // code }

Q109

Q109 How do you call a base class method from a derived class in C#?

A

base.MyMethod();

B

this.MyMethod();

C

super.MyMethod();

D

parent.MyMethod();

Q110

Q110 You get an error 'cannot create an instance of the abstract class'.
What is the likely cause?

A

Trying to instantiate an abstract class

B

Calling an undefined method

C

Accessing private members

D

Incorrect inheritance

Q111

Q111 You encounter a 'method not overridden' warning.
What could be the issue?

A

The method in the base class is not marked as virtual

B

The method in the derived class is not marked as override

C

The method signatures do not match

D

All of the above

Q112

Q112 What is an interface in C#?

A

A class with implemented methods

B

A class with only private methods

C

A contract with no implementation

D

A method without a class

Q113

Q113 Which keyword is used to implement an interface in a class?

A

extends

B

implements

C

inherits

D

:

Q114

Q114 What is the main purpose of an abstract class in C#?

A

To provide a blueprint for derived classes

B

To allow multiple inheritance

C

To store constant values

D

To implement interfaces

Q115

Q115 Which of the following statements is true about abstract classes in C#?

A

Abstract classes can be instantiated

B

Abstract classes cannot contain implemented methods

C

Abstract classes can inherit from multiple classes

D

Abstract classes can have constructors

Q116

Q116 What is the difference between an interface and an abstract class in C#?

A

An interface can have fields, an abstract class cannot

B

An abstract class can have implementations, an interface cannot

C

An interface supports multiple inheritance, an abstract class does not

D

All of the above

Q117

Q117 How do you define an interface in C#?

A

interface IMyInterface { // code }

B

public interface IMyInterface { // code }

C

class IMyInterface { // code }

D

struct IMyInterface { // code }

Q118

Q118 How do you implement an interface method in a class in C#?

A

public void InterfaceMethod() { // code }

B

public void IMyInterface.InterfaceMethod() { // code }

C

public void InterfaceMethod() override { // code }

D

public void InterfaceMethod() implements { // code }

Q119

Q119 You get an error 'does not implement interface member'.
What is the likely cause?

A

The class does not provide implementations for all interface methods

B

The interface is not defined

C

The class is abstract

D

The class does not inherit the interface

Q120

Q120 You encounter an error 'cannot create an instance of an interface'.
What could be the cause?

A

Trying to instantiate an interface

B

Implementing the interface incorrectly

C

Using incorrect syntax

D

Interface name conflict

ad verticalad vertical
ad