A developer implements IComparable interface in a Student class. What must the class implement?
Answer: A
IComparable interface requires implementing the CompareTo() method, which defines how objects of the class should be compared for sorting purposes.
Q.162Hard
What will happen if you try to override a non-virtual method in a derived class in C#?
Answer: B
In C#, if you attempt to override a non-virtual method without using 'new' keyword, the compiler issues a warning but the method is hidden (not overridden). Using 'new' keyword explicitly hides the base method.
Q.163Hard
A banking application uses inheritance where Account is the parent class and SavingsAccount, CurrentAccount are derived classes. Each has different withdrawal rules. Which design principle is being followed?
Answer: B
Open/Closed Principle states that classes should be open for extension (SavingsAccount, CurrentAccount extend Account) but closed for modification (Account class rules remain unchanged). This is a classic example of OCP.
Q.164Medium
What is the correct order of constructor execution in multilevel inheritance?
class A { public A() { Console.WriteLine("A"); } }
class B : A { public B() { Console.WriteLine("B"); } }
class C : B { public C() { Console.WriteLine("C"); } }
new C();
Answer: B
Constructor execution follows from parent to child. When C() is called, it implicitly calls B() which calls A(). So output is: A B C. Base class constructors execute before derived class constructors.
Q.165Medium
An e-commerce system needs to ensure that a Product class cannot be instantiated directly but can be inherited. Additionally, it must define some concrete methods and some abstract methods. Which approach is best?
Answer: C
Abstract classes can have both concrete (implemented) and abstract (unimplemented) methods. They cannot be instantiated directly but can be inherited. This perfectly fits the requirement.
Advertisement
Q.166Easy
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);
Answer: C
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.
Q.167Medium
A payment processing system implements multiple interfaces: IPayment, IRefundable, IAuditTrail. A PaymentProcessor class must implement all three. Which statement is true?
Answer: C
C# supports multiple interface implementation. A class can implement multiple interfaces separated by commas, and must implement all abstract members of each interface.
Q.168Easy
Which of the following best describes the 'this' keyword in C#?
Answer: B
'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.
Q.169Hard
In a hospital management system, Doctor and Nurse classes need to perform a common Logout() operation but have different Login() procedures. What is the best OOP approach?
Answer: A
A base class with virtual Logout() allows common implementation, while abstract Login() forces derived classes to provide their own implementation. This combines code reuse with flexibility.
Q.170Easy
What is the primary purpose of ASP.NET in web development?
Answer: A
ASP.NET is a server-side web application framework developed by Microsoft for building dynamic, interactive web applications.
Q.171Easy
Which of the following is the latest version of ASP.NET as per 2024-2025?
Answer: B
ASP.NET Core 8.0 is the latest unified platform as of 2024-2025, replacing the older ASP.NET Framework.
Q.172Easy
What does CLR stand for in the context of .NET?
Answer: A
CLR (Common Language Runtime) is the virtual machine that executes .NET code, managing memory, security, and type safety.
Q.173Medium
In ASP.NET, what is the purpose of the Global.asax file?
Answer: A
Global.asax handles application-level events like Application_Start, Application_End, and Session_Start.
Q.174Medium
Which attribute is used to mark a method as an HTTP endpoint in ASP.NET Core?
Answer: B
[HttpGet], [HttpPost], [HttpPut], [HttpDelete] attributes define HTTP methods for controller actions in ASP.NET Core.
Q.175Medium
What is the difference between ASP.NET Framework and ASP.NET Core?
Answer: A
ASP.NET Core is cross-platform (Windows, Linux, macOS) and open-source, while ASP.NET Framework is Windows-only.
Q.176Medium
Which of the following is NOT a built-in state management technique in ASP.NET?
Answer: D
ViewState, Session State, Application State, and Cookies are valid state management techniques. Block State is not a standard ASP.NET technique.
Q.177Medium
What is the role of Middleware in ASP.NET Core?
Answer: A
Middleware components handle cross-cutting concerns like authentication, logging, and exception handling in the request pipeline.
Q.178Medium
In an ASP.NET Core application, where is Dependency Injection configured?
Answer: A
Dependency Injection is configured in the ConfigureServices method of Startup.cs (or Program.cs in newer versions).
Q.179Medium
What is the purpose of the [ValidateAntiForgeryToken] attribute in ASP.NET MVC?
Answer: A
[ValidateAntiForgeryToken] verifies that form submissions come from your application, preventing CSRF attacks.
Q.180Medium
Which of the following methods is used to pass data from Controller to View in ASP.NET MVC?
Answer: A
ViewBag (dynamic) and ViewData (dictionary) are common ways to pass data from Controller to View in ASP.NET MVC.