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 41–50 of 76
Topics in C# Programming
Q.41 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.42 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.43 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
Q.44 Easy OOP in C#
Which of the following correctly demonstrates an abstract class with an abstract method in C#?
A public abstract class Base { public abstract void Method(); }
B public class Base { public abstract void Method(); }
C public abstract class Base { public void Method(); }
D public sealed abstract class Base { public abstract void Method(); }
Correct Answer:  A. public abstract class Base { public abstract void Method(); }
EXPLANATION

An abstract class uses the 'abstract' keyword, and abstract methods must be declared without implementation inside abstract classes.

Test
Q.45 Easy OOP in C#
In C#, can a class inherit from multiple classes?
A Yes, always
B No, C# does not support multiple inheritance
C Yes, but only if they are abstract
D Yes, using the 'multiple' keyword
Correct Answer:  B. No, C# does not support multiple inheritance
EXPLANATION

C# does not support multiple class inheritance to avoid the diamond problem. However, a class can implement multiple interfaces.

Test
Q.46 Easy OOP in C#
Which keyword is used to create a derived class in C#?
A extends
B inherits
C :
D ->
Correct Answer:  C. :
EXPLANATION

In C#, the colon (:) is used to indicate inheritance. For example, 'class Child : Parent' creates a derived class.

Test
Q.47 Easy OOP in C#
In C#, what is the default access modifier for class members?
A public
B private
C protected
D internal
Correct Answer:  B. private
EXPLANATION

The default access modifier for class members in C# is 'private', which restricts access to within the class only.

Test
Q.48 Easy Basics & Syntax
Which of the following is a correct way to declare a property with auto-implementation in C#?
A public int Age { get; set; }
B public int Age() { get; set; }
C public Age int { get; set; }
D public int get Age; set;
Correct Answer:  A. public int Age { get; set; }
EXPLANATION

Auto-implemented properties in C# use the syntax: public Type PropertyName { get; set; } without explicitly defining the backing field.

Test
Q.49 Easy Basics & Syntax
Consider this code: int[] arr = new int[5]; foreach(var item in arr) { Console.Write(item + " "); } What is the output?
A Nothing (empty output)
B 0 0 0 0 0
C Throws an IndexOutOfRangeException
D Null Null Null Null Null
Correct Answer:  B. 0 0 0 0 0
EXPLANATION

Arrays in C# are automatically initialized with default values. For int arrays, the default value is 0. Therefore, the output will be five zeros separated by spaces.

Test
Q.50 Easy Basics & Syntax
Which collection type in C# is best suited for key-value pair storage with unique keys?
A List
B Dictionary
C HashSet
D Queue
Correct Answer:  B. Dictionary
EXPLANATION

Dictionary<K, V> stores key-value pairs and ensures unique keys. List stores ordered values, HashSet stores unique values only, Queue is FIFO.

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