Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

60 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–50 of 60
Topics in C# Programming
Q.41 Hard OOP in C#
In C#, what happens when you apply the 'static' modifier to a method inside an interface (C# 11+)?
A The method must be implemented by all implementing classes
B The method provides a default implementation and can be called without instantiation
C It causes a compile-time error
D The method becomes abstract and requires override
Correct Answer:  B. The method provides a default implementation and can be called without instantiation
EXPLANATION

C# 11 allows static abstract members in interfaces. Static methods in interfaces provide default implementations and can be called via the interface type.

Test
Q.42 Hard OOP in C#
What is the output of the following code?
class Base { public virtual void Method() { Console.WriteLine("Base"); } }
class Derived : Base { public override void Method() { base.Method(); Console.WriteLine("Derived"); } }
Derived d = new Derived();
d.Method();
A Base
B Derived
C BaseDerived
D Compilation Error
Correct Answer:  C. BaseDerived
EXPLANATION

The 'base' keyword calls the parent class method first, printing 'Base', then the derived method prints 'Derived'. Output: 'BaseDerived'.

Test
Q.43 Hard OOP in C#
What will happen if you try to override a non-virtual method?
A It will override successfully
B Compilation error - cannot override non-virtual method
C It will use method hiding instead
D Runtime exception
Correct Answer:  B. Compilation error - cannot override non-virtual method
EXPLANATION

To override a method, it must be marked as 'virtual' in the base class. Attempting to override a non-virtual method causes a compilation error.

Test
Q.44 Hard OOP in C#
Consider the following code. What will be the output?
interface I1 { void Show(); }
interface I2 { void Show(); }
class C : I1, I2 { public void Show() { Console.WriteLine("C"); } }
C obj = new C();
obj.Show();
A C
B Compilation Error
C I1
D I2
Correct Answer:  A. C
EXPLANATION

A single method implementation satisfies both interface contracts. The method is called and prints 'C'.

Test
Q.45 Hard OOP in C#
What is the output of the following?
class A { public void Test() { Console.WriteLine("A"); } }
class B : A { public new void Test() { Console.WriteLine("B"); } }
A a = new B();
a.Test();
A A
B B
C AB
D Compilation Error
Correct Answer:  A. A
EXPLANATION

Using 'new' keyword hides the method. Since reference is of type A, A's Test() is called. Output is 'A'.

Test
Q.46 Hard Basics & Syntax
In C# 2024, which feature allows you to use pattern matching to deconstruct objects and filter simultaneously in a single expression?
A List patterns with logical operators
B Record types with positional parameters
C Nullable reference types
D Anonymous methods
Correct Answer:  A. List patterns with logical operators
EXPLANATION

C# 12 (2024) introduced advanced list patterns that allow filtering and deconstructing collections in pattern matching expressions, improving code readability and efficiency.

Test
Q.47 Hard Basics & Syntax
What is the output of: string s = "Hello"; Console.WriteLine(s.GetHashCode() == s.GetHashCode());
A true
B false
C NullReferenceException
D Compiler Error
Correct Answer:  A. true
EXPLANATION

GetHashCode() on the same string returns the same hash code value, so comparison is true. Strings are immutable in C#.

Test
Q.48 Hard Basics & Syntax
In C# 2024, what is the latest feature for null-safety introduced in recent versions?
A Nullable reference types
B required keyword for properties
C init-only properties
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

C# has progressively introduced nullable reference types, required keyword (C# 11), and init-only properties (C# 9) for better null-safety and immutability.

Test
Q.49 Hard Basics & Syntax
What will be the output of: decimal price = 19.99m; Console.WriteLine(price.GetType().Name);
A "Decimal"
B "decimal"
C "Double"
D "Single"
Correct Answer:  A. "Decimal"
EXPLANATION

The GetType().Name returns the type name as "Decimal" (capitalized). The 'm' suffix specifies a decimal literal. The output shows the CLR type name, which is "Decimal".

Test
Q.50 Hard Basics & Syntax
In C#, which keyword is used to implement multiple interface inheritance?
A extend
B inherit
C implements
D A class inherits by directly listing interfaces separated by commas
Correct Answer:  D. A class inherits by directly listing interfaces separated by commas
EXPLANATION

C# implements multiple interface inheritance by listing interfaces separated by commas after the class name: class MyClass : Interface1, Interface2. There is no 'extends' or 'implements' keyword in C#.

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