Home Subjects C# Programming OOP in C#

C# Programming
OOP in C#

C# and .NET for campus placement

24 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 24
Topics in C# Programming
Q.1 Easy OOP in C#
Consider a payment processing system where PaymentProcessor is an abstract class with an abstract method ProcessPayment(). CreditCardProcessor and UPIProcessor are derived classes. What will happen if you try to instantiate PaymentProcessor directly in C#?
A It will compile successfully and create an instance with default implementations
B Compiler error - cannot instantiate an abstract class
C Runtime error - abstract class cannot be instantiated at runtime
D It will compile but throw an error only if ProcessPayment() is called
Correct Answer:  B. Compiler error - cannot instantiate an abstract class
EXPLANATION

Abstract classes in C# cannot be instantiated directly. The compiler enforces this rule at compile-time. Abstract classes serve as blueprints and must be inherited by concrete classes that provide implementations for all abstract members. This ensures proper design and forces derived classes to implement required functionality.

Test
Q.2 Easy OOP in C#
Which statement is TRUE about abstract methods in C#?
A Abstract methods must be implemented in the base class
B Abstract methods cannot have any body and must be implemented in derived classes
C Abstract methods are only for static classes
D Abstract methods can be private
Correct Answer:  B. Abstract methods cannot have any body and must be implemented in derived classes
EXPLANATION

Abstract methods have no implementation in the abstract class and force derived classes to provide their own implementation. They cannot be private as they must be overridable.

Test
Q.3 Easy OOP in C#
In C#, what is the primary purpose of using an interface?
A To provide complete implementation of methods
B To define a contract that classes must implement
C To create a concrete object directly
D To restrict inheritance to a single class
Correct Answer:  B. To define a contract that classes must implement
EXPLANATION

Interfaces in C# define a set of method and property declarations that implementing classes must provide, establishing a contract without implementation details.

Test
Q.4 Easy OOP in C#
Which of the following is NOT a pillar of OOP in C#?
A Inheritance
B Polymorphism
C Encapsulation
D Compilation
Correct Answer:  D. Compilation
EXPLANATION

The four pillars of OOP are Inheritance, Polymorphism, Encapsulation, and Abstraction. Compilation is a language feature, not an OOP principle.

Test
Q.5 Easy OOP in C#
In C#, what is the correct syntax to implement multiple interfaces in a class?
A class MyClass : Interface1, Interface2 { }
B class MyClass implements Interface1, Interface2 { }
C class MyClass : Interface1 : Interface2 { }
D class MyClass inherits Interface1, Interface2 { }
Correct Answer:  A. class MyClass : Interface1, Interface2 { }
EXPLANATION

C# uses colon (:) to implement interfaces, and multiple interfaces are separated by commas. The 'implements' keyword is used in Java, not C#.

Test
Q.6 Easy OOP in C#
Which keyword is used to create a class that cannot be instantiated in C#?
A sealed
B abstract
C static
D readonly
Correct Answer:  B. abstract
EXPLANATION

The 'abstract' keyword prevents instantiation of a class and forces derived classes to implement abstract members, establishing a contract for subclasses.

Test
Q.7 Easy OOP in C#
What is the primary purpose of encapsulation in OOP?
A To increase code execution speed
B To hide internal implementation details and control access to data
C To reduce memory consumption
D To allow multiple inheritance
Correct Answer:  B. To hide internal implementation details and control access to data
EXPLANATION

Encapsulation bundles data and methods together, hiding internal implementation and controlling access through public interfaces, improving maintainability and security.

Test
Q.8 Easy OOP in C#
Which of the following best describes the 'this' keyword in C#?
A Refers to the parent class instance
B Refers to the current instance of the class
C Refers to the static members of the class
D Refers to the class definition itself
Correct Answer:  B. Refers to the current instance of the class
EXPLANATION

'this' keyword represents the current instance of the class. It is used to access instance members, differentiate between local and instance variables, and pass the current object as a parameter.

Test
Q.9 Easy OOP in C#
What is the output of this C# code?

public class Employee
{
private string name = "John";
public Employee(string n) { name = n; }
}
Employee emp = new Employee("Alice");
Console.WriteLine(emp.name);
A John
B Alice
C Compilation error - 'name' is inaccessible
D Runtime error
Correct Answer:  C. Compilation error - 'name' is inaccessible
EXPLANATION

The 'name' field is declared as 'private', so it cannot be accessed outside the class. Attempting to access emp.name from outside the class results in a compilation error.

Test
Q.10 Easy OOP in C#
What is the purpose of the 'base' keyword in C#?
A To access static members of the current class
B To refer to members of the parent class
C To create a new instance of the current class
D To declare a variable as immutable
Correct Answer:  B. To refer to members of the parent class
EXPLANATION

The 'base' keyword allows a derived class to access members (methods, properties, constructors) of the parent class. It's commonly used to call the parent constructor or override methods while keeping parent functionality.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips