Guest User

Untitled

a guest
Mar 16th, 2025
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.14 KB | None | 0 0
  1. Front Back
  2. What are the four main principles of Object-Oriented Programming (OOP)? Encapsulation, Abstraction, Inheritance, and Polymorphism.
  3. What is encapsulation in C#? Encapsulation is the practice of restricting access to certain details of an object and only exposing what is necessary.
  4. How do you implement encapsulation in C#? By using access modifiers like `private`, `protected`, and `public` to control visibility.
  5. 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.
  6. What is abstraction in C#? Abstraction hides complex implementation details and only exposes essential parts through interfaces or abstract classes.
  7. What is an abstract class in C#? A class that cannot be instantiated and must be inherited, containing abstract and/or concrete methods.
  8. How do you define an abstract class in C#? Using the `abstract` keyword: `abstract class MyClass { public abstract void DoSomething(); }`
  9. What is the difference between an abstract class and an interface? Abstract classes can have implementations, while interfaces only define contracts without implementation.
  10. What is inheritance in C#? Inheritance allows a class to derive functionality from another class, reducing redundancy and promoting reusability.
  11. How do you define inheritance in C#? By using `:` to extend a class: `class ChildClass : ParentClass { }`
  12. What is the base keyword used for? It allows a derived class to call a constructor or method from its base class.
  13. How do you call a base class constructor from a derived class? Using `base(parameters)`: `class Child : Parent { public Child() : base(value) { } }`
  14. What is polymorphism in C#? Polymorphism allows methods to take different forms—either method overriding or method overloading.
  15. What is method overloading? Method overloading is defining multiple methods with the same name but different parameter lists.
  16. What is method overriding? Method overriding is redefining a base class method in a derived class using the `override` keyword.
  17. 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.
  18. 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.
  19. What is the purpose of the `sealed` keyword? It prevents a class from being inherited or a method from being overridden.
  20. What is an interface in C#? An interface defines a contract that classes must implement without providing implementations.
  21. How do you define an interface in C#? Using the `interface` keyword: `interface IMyInterface { void MyMethod(); }`
  22. What is the difference between implementing multiple interfaces and inheriting from a class? A class can inherit only one class but implement multiple interfaces.
  23. How do you implement an interface in C#? By specifying the interface in the class definition: `class MyClass : IMyInterface { public void MyMethod() { } }`
  24. What is an explicit interface implementation? A way to implement an interface method that does not expose it publicly: `void IMyInterface.Method() { }`
  25. How do you check if an object implements an interface? Using `obj is IMyInterface` or `obj as IMyInterface`.
  26. What is the difference between an `interface` and an `abstract class`? An abstract class can have constructors and fields, while an interface cannot.
  27. What is a constructor in C#? A special method that initializes a class when an instance is created.
  28. What is a destructor in C#? A method (`~ClassName()`) that runs when an object is garbage collected.
  29. How do you prevent a class from being instantiated? By making it `abstract` or `sealed` with a private constructor.
  30. What is the `this` keyword used for? It refers to the current instance of a class.
  31. What is the `static` keyword used for in a class? It defines members that belong to the class itself rather than instances.
  32. How do you create a singleton class in C#? By using a `static readonly` instance with a private constructor.
  33. What is a partial class in C#? A class whose definition is split across multiple files using the `partial` keyword.
  34. What is a nested class in C#? A class defined inside another class, used to encapsulate closely related logic.
  35. How do you create an extension method? By defining a static method with `this` as the first parameter.
  36. What is operator overloading in C#? A way to redefine operators for custom classes: `public static MyClass operator +(MyClass a, MyClass b) { }`
  37. 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; }`
  38. What is a virtual property in C#? A property that can be overridden in derived classes using the `virtual` and `override` keywords.
  39. 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() { }`
  40. What is a factory method? A static method that creates and returns instances of a class.
  41. What is dependency injection in OOP? A design pattern where dependencies are passed into a class rather than created inside it.
  42. How do you implement dependency injection in C#? By using constructor injection: `public MyClass(IMyService service) { _service = service; }`
  43. What is an aggregate root in domain-driven design (DDD)? An entity that controls access to a group of related entities.
  44. What is an anti-pattern in OOP? A design that appears beneficial but has negative consequences, such as the "God Object."
  45. What is the Liskov Substitution Principle (LSP)? Objects of a derived class should be replaceable with objects of the base class without altering behavior.
  46. What is the Open/Closed Principle (OCP)? A class should be open for extension but closed for modification.
  47. What is the Single Responsibility Principle (SRP)? A class should have only one reason to change.
  48. What is the Dependency Inversion Principle (DIP)? High-level modules should not depend on low-level modules, but on abstractions.
  49. What is the Interface Segregation Principle (ISP)? A class should not be forced to implement interfaces it does not use.
  50. How do you apply the SOLID principles in C#? By using encapsulation, DI, interfaces, and separation of concerns.
  51. What is the Repository Pattern? A pattern that abstracts data access logic from business logic.
  52. What is the Unit of Work pattern? A pattern that maintains consistency by coordinating multiple repositories in a single transaction.
  53. 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.
  54. What is a Value Object in DDD? An immutable object that has no identity and is defined by its properties.
  55. How do you implement a Value Object in C#? By overriding `Equals()` and `GetHashCode()` to compare values instead of references.
  56. 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