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 11–20 of 24
Topics in C# Programming
Q.11 Easy OOP in C#
Which of the following best describes encapsulation in C#?
A Wrapping data and methods together and hiding internal details using access modifiers
B Creating multiple instances of the same class
C Inheriting properties from a parent class
D Using interfaces to define contracts
Correct Answer:  A. Wrapping data and methods together and hiding internal details using access modifiers
EXPLANATION

Encapsulation is the bundling of data (variables) and methods (functions) into a single unit (class) while hiding the internal details. Access modifiers like private, protected, and public control visibility.

Test
Q.12 Easy OOP in C#
In C# inheritance, which keyword allows accessing members of the parent class?
A this
B base
C parent
D super
Correct Answer:  B. base
EXPLANATION

The 'base' keyword is used to access members (properties, methods) of the parent class from within derived class methods, particularly in constructors and method overriding.

Test
Q.13 Easy OOP in C#
What is the primary purpose of using interfaces in C#?
A To store data members
B To define a contract for classes implementing them
C To improve code performance
D To reduce memory usage
Correct Answer:  B. To define a contract for classes implementing them
EXPLANATION

Interfaces define a contract that classes must implement, ensuring consistent method signatures across different implementations. They enable polymorphism and loose coupling.

Test
Q.14 Easy OOP in C#
In C#, which access modifier allows a member to be accessed only within the same class?
A private
B protected
C internal
D public
Correct Answer:  A. private
EXPLANATION

The 'private' access modifier restricts access to members within the same class only. It is the most restrictive access level in C#.

Test
Q.15 Easy OOP in C#
What is the output behavior of ToString() method when not overridden in a custom class?
A Returns an empty string
B Returns the fully qualified name of the class
C Returns null
D Throws a NotImplementedException
Correct Answer:  B. Returns the fully qualified name of the class
EXPLANATION

Default ToString() (inherited from object) returns the fully qualified namespace and class name. Custom implementations are recommended for meaningful string representation.

Test
Q.16 Easy OOP in C#
Which of the following demonstrates proper encapsulation in C#?
A public int age; public void SetAge(int a) { age = a; }
B private int age; public int Age { get; set; }
C public int age { get; set; }
D internal int age; public int GetAge() { return age; }
Correct Answer:  B. private int age; public int Age { get; set; }
EXPLANATION

Proper encapsulation uses private fields with public properties, providing controlled access and allowing for future validation logic.

Test
Q.17 Easy OOP in C#
What does the 'base' keyword do in a derived class method in C#?
A References the current class instance
B References the base class instance and its members
C Creates a new base class object
D Marks the method as abstract
Correct Answer:  B. References the base class instance and its members
EXPLANATION

'base' keyword is used to access base class members, particularly useful in constructors to call base class constructors or override base methods.

Test
Q.18 Easy OOP in C#
What happens when you mark a class with the 'sealed' modifier?
A The class cannot have any public members
B The class cannot be inherited from
C The class cannot be instantiated
D The class cannot have virtual methods
Correct Answer:  B. The class cannot be inherited from
EXPLANATION

'sealed' keyword prevents a class from being inherited. This is useful for security and performance optimization when you want to prevent further derivation.

Test
Q.19 Easy OOP in C#
What is the output of using 'nameof()' operator on a property in C#?
A Returns the property value
B Returns the property name as a string
C Returns the property type
D Returns a null reference
Correct Answer:  B. Returns the property name as a string
EXPLANATION

'nameof()' operator (C# 6+) returns the name of a variable, type, or member as a string literal, useful for logging and validation.

Test
Q.20 Easy OOP in C#
Which access modifier allows a member to be accessed only within the same assembly?
A private
B internal
C protected internal
D public
Correct Answer:  B. internal
EXPLANATION

'internal' access modifier restricts member access to the same assembly only. This is useful for creating assembly-wide internal APIs.

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