Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

76 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 76
Topics in C# Programming
Q.31 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.32 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.33 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
Q.34 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.35 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.36 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.37 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.38 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.39 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.40 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
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