Home Subjects C# Programming OOP in C#

C# Programming
OOP in C#

C# and .NET for campus placement

51 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–50 of 51
Topics in C# Programming
Q.41 Medium OOP in C#
What is the primary difference between method overloading and method overriding in C#?
A Overloading changes method signature, overriding changes method behavior in derived classes
B Overloading is used for inheritance, overriding is used for polymorphism
C Overloading requires virtual keyword, overriding requires abstract keyword
D Overloading is compile-time, overriding is run-time
Correct Answer:  A. Overloading changes method signature, overriding changes method behavior in derived classes
EXPLANATION

Overloading creates multiple methods with the same name but different parameters. Overriding replaces a base class method in a derived class.

Test
Q.42 Medium OOP in C#
What is the output when you access a property marked with 'init' accessor after object initialization in C#?
A Returns the value normally
B Throws a compile-time error if you try to modify it
C Returns null
D Throws a runtime InvalidOperationException
Correct Answer:  B. Throws a compile-time error if you try to modify it
EXPLANATION

The 'init' accessor (introduced in C# 9) allows setting the property only during initialization. Any modification attempt post-initialization causes a compile-time error.

Test
Q.43 Medium OOP in C#
In C# 11, which feature allows you to define required members in a class?
A Using the 'required' keyword on properties
B Using the 'mandatory' keyword on fields
C Using the 'essential' keyword on methods
D Using the 'compulsory' keyword on constructors
Correct Answer:  A. Using the 'required' keyword on properties
EXPLANATION

C# 11 introduced the 'required' keyword that enforces callers to initialize specific members during object instantiation.

Test
Q.44 Medium OOP in C#
In C# 2024-25, which feature allows defining read-only properties with automatic backing fields?
A Auto-properties with init accessor
B Readonly keyword
C Private setters only
D Const properties
Correct Answer:  A. Auto-properties with init accessor
EXPLANATION

C# auto-properties with 'init' accessor allow creating read-only properties that can only be set during initialization, improving encapsulation.

Test
Q.45 Medium OOP in C#
Which of the following represents proper use of constructor chaining in C#?
A class Child { Child() : base() { } }
B class Child { Child(int x) : this() { } }
C class Child { Child() : Child(5) { } }
D class Child { Child() { Child(5); } }
Correct Answer:  B. class Child { Child(int x) : this() { } }
EXPLANATION

Constructor chaining uses 'this()' to call another constructor in the same class. Option B shows proper syntax for calling a parameterless constructor.

Test
Q.46 Medium OOP in C#
In C#, what is the difference between a class and a struct?
A Classes are reference types, structs are value types
B Structs are reference types, classes are value types
C They are identical
D Structs cannot have methods
Correct Answer:  A. Classes are reference types, structs are value types
EXPLANATION

Classes are reference types stored on heap, structs are value types stored on stack. This affects memory management and behavior.

Test
Q.47 Medium OOP in C#
What is the purpose of the 'sealed' keyword in C#?
A To prevent a class or method from being inherited or overridden
B To make a class public
C To encrypt the code
D To optimize performance
Correct Answer:  A. To prevent a class or method from being inherited or overridden
EXPLANATION

The 'sealed' keyword prevents a class from being inherited or a method from being overridden in derived classes.

Test
Q.48 Medium OOP in C#
Which of the following is true about properties in C#?
A Properties can only have getters
B Properties are slower than direct field access
C Properties provide encapsulation while maintaining clean syntax
D Properties cannot validate data
Correct Answer:  C. Properties provide encapsulation while maintaining clean syntax
EXPLANATION

Properties in C# allow controlled access to fields with validation logic while maintaining clean, intuitive syntax like field access.

Test
Q.49 Medium OOP in C#
In C#, which interface is used to implement custom iteration logic?
A IEnumerable
B IIterable
C ICollection
D IList
Correct Answer:  A. IEnumerable
EXPLANATION

IEnumerable interface in C# is used to provide iteration capability through the GetEnumerator() method.

Test
Q.50 Medium OOP in C#
What is the difference between 'new' keyword and 'override' keyword in C#?
A 'new' hides the base class method, 'override' replaces it
B 'override' hides the base class method, 'new' replaces it
C They are functionally identical
D 'new' is used for interfaces, 'override' for classes
Correct Answer:  A. 'new' hides the base class method, 'override' replaces it
EXPLANATION

'new' keyword hides the base class method (method hiding), while 'override' provides true polymorphic behavior by replacing the method.

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