Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Front Back
- What are the four main principles of Object-Oriented Programming (OOP)? Encapsulation, Abstraction, Inheritance, and Polymorphism.
- What is encapsulation in C#? Encapsulation is the practice of restricting access to certain details of an object and only exposing what is necessary.
- How do you implement encapsulation in C#? By using access modifiers like `private`, `protected`, and `public` to control visibility.
- What is the difference between `private`, `protected`, and `public` in C#? `private` restricts access to the same class, `protected` allows access from derived classes, and `public` makes members accessible from anywhere.
- What is abstraction in C#? Abstraction hides complex implementation details and only exposes essential parts through interfaces or abstract classes.
- What is an abstract class in C#? A class that cannot be instantiated and must be inherited, containing abstract and/or concrete methods.
- How do you define an abstract class in C#? Using the `abstract` keyword: `abstract class MyClass { public abstract void DoSomething(); }`
- What is the difference between an abstract class and an interface? Abstract classes can have implementations, while interfaces only define contracts without implementation.
- What is inheritance in C#? Inheritance allows a class to derive functionality from another class, reducing redundancy and promoting reusability.
- How do you define inheritance in C#? By using `:` to extend a class: `class ChildClass : ParentClass { }`
- What is the base keyword used for? It allows a derived class to call a constructor or method from its base class.
- How do you call a base class constructor from a derived class? Using `base(parameters)`: `class Child : Parent { public Child() : base(value) { } }`
- What is polymorphism in C#? Polymorphism allows methods to take different forms—either method overriding or method overloading.
- What is method overloading? Method overloading is defining multiple methods with the same name but different parameter lists.
- What is method overriding? Method overriding is redefining a base class method in a derived class using the `override` keyword.
- What is the difference between `override`, `new`, and `virtual` keywords? `virtual` allows overriding, `override` replaces the base method, and `new` hides the base method without overriding it.
- What is the difference between method hiding and method overriding? Method hiding (`new`) creates a new implementation that hides the base method, while method overriding (`override`) replaces it.
- What is the purpose of the `sealed` keyword? It prevents a class from being inherited or a method from being overridden.
- What is an interface in C#? An interface defines a contract that classes must implement without providing implementations.
- How do you define an interface in C#? Using the `interface` keyword: `interface IMyInterface { void MyMethod(); }`
- What is the difference between implementing multiple interfaces and inheriting from a class? A class can inherit only one class but implement multiple interfaces.
- How do you implement an interface in C#? By specifying the interface in the class definition: `class MyClass : IMyInterface { public void MyMethod() { } }`
- What is an explicit interface implementation? A way to implement an interface method that does not expose it publicly: `void IMyInterface.Method() { }`
- How do you check if an object implements an interface? Using `obj is IMyInterface` or `obj as IMyInterface`.
- What is the difference between an `interface` and an `abstract class`? An abstract class can have constructors and fields, while an interface cannot.
- What is a constructor in C#? A special method that initializes a class when an instance is created.
- What is a destructor in C#? A method (`~ClassName()`) that runs when an object is garbage collected.
- How do you prevent a class from being instantiated? By making it `abstract` or `sealed` with a private constructor.
- What is the `this` keyword used for? It refers to the current instance of a class.
- What is the `static` keyword used for in a class? It defines members that belong to the class itself rather than instances.
- How do you create a singleton class in C#? By using a `static readonly` instance with a private constructor.
- What is a partial class in C#? A class whose definition is split across multiple files using the `partial` keyword.
- What is a nested class in C#? A class defined inside another class, used to encapsulate closely related logic.
- How do you create an extension method? By defining a static method with `this` as the first parameter.
- What is operator overloading in C#? A way to redefine operators for custom classes: `public static MyClass operator +(MyClass a, MyClass b) { }`
- How do you implement an indexer in C#? Using `this` to define array-like access to class members: `public int this[int index] { get; set; }`
- What is a virtual property in C#? A property that can be overridden in derived classes using the `virtual` and `override` keywords.
- How do you prevent a method from being overridden in a derived class? By marking it with the `sealed` keyword: `public sealed override void Method() { }`
- What is a factory method? A static method that creates and returns instances of a class.
- What is dependency injection in OOP? A design pattern where dependencies are passed into a class rather than created inside it.
- How do you implement dependency injection in C#? By using constructor injection: `public MyClass(IMyService service) { _service = service; }`
- What is an aggregate root in domain-driven design (DDD)? An entity that controls access to a group of related entities.
- What is an anti-pattern in OOP? A design that appears beneficial but has negative consequences, such as the "God Object."
- What is the Liskov Substitution Principle (LSP)? Objects of a derived class should be replaceable with objects of the base class without altering behavior.
- What is the Open/Closed Principle (OCP)? A class should be open for extension but closed for modification.
- What is the Single Responsibility Principle (SRP)? A class should have only one reason to change.
- What is the Dependency Inversion Principle (DIP)? High-level modules should not depend on low-level modules, but on abstractions.
- What is the Interface Segregation Principle (ISP)? A class should not be forced to implement interfaces it does not use.
- How do you apply the SOLID principles in C#? By using encapsulation, DI, interfaces, and separation of concerns.
- What is the Repository Pattern? A pattern that abstracts data access logic from business logic.
- What is the Unit of Work pattern? A pattern that maintains consistency by coordinating multiple repositories in a single transaction.
- What is the purpose of a DTO (Data Transfer Object)? A DTO is used to transfer data between layers while preventing direct exposure of domain models.
- What is a Value Object in DDD? An immutable object that has no identity and is defined by its properties.
- How do you implement a Value Object in C#? By overriding `Equals()` and `GetHashCode()` to compare values instead of references.
- What is the difference between a domain model and a DTO? A domain model contains business logic, while a DTO is a simple container for transferring data.
Advertisement
Add Comment
Please, Sign In to add comment