Govt. Exams
Entrance Exams
Encapsulation is the bundling of data (variables) and methods (functions) into a single unit (class) while hiding the internal details. Access modifiers like private, protected, and public control visibility.
The 'base' keyword is used to access members (properties, methods) of the parent class from within derived class methods, particularly in constructors and method overriding.
Interfaces define a contract that classes must implement, ensuring consistent method signatures across different implementations. They enable polymorphism and loose coupling.
The 'private' access modifier restricts access to members within the same class only. It is the most restrictive access level in C#.
Default ToString() (inherited from object) returns the fully qualified namespace and class name. Custom implementations are recommended for meaningful string representation.
Proper encapsulation uses private fields with public properties, providing controlled access and allowing for future validation logic.
'base' keyword is used to access base class members, particularly useful in constructors to call base class constructors or override base methods.
'sealed' keyword prevents a class from being inherited. This is useful for security and performance optimization when you want to prevent further derivation.
'nameof()' operator (C# 6+) returns the name of a variable, type, or member as a string literal, useful for logging and validation.
'internal' access modifier restricts member access to the same assembly only. This is useful for creating assembly-wide internal APIs.