Govt. Exams
Entrance Exams
The 'base' keyword in the constructor initialization list ensures the parent class constructor is called before the derived class constructor body executes, maintaining proper initialization order.
C# allows one implementation to satisfy multiple interfaces when they have the same method signature. Explicit interface implementation can be used if methods need different behaviors.
The sealed keyword on a virtual method prevents overriding in derived classes, ensuring that implementation is locked in the current class.
IEquatable<T> provides type-safe equality comparison, improves performance by avoiding boxing, and is essential for proper behavior in collections like Dictionary.
C# doesn't support multiple inheritance of classes, but allows one base class and multiple interfaces, providing flexibility while maintaining hierarchy.
Inheritance and polymorphism provide better maintainability, scalability, and follow SOLID principles compared to conditional logic.
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.
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.
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.
Strategy pattern defines a family of algorithms (logger types) and makes them interchangeable through interface polymorphism, allowing runtime selection.