Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Both can define contracts for derived classes. Both support polymorphism. Both cannot be instantiated directly. Both can be used with dependency injection. Real-world example (ShopNest) Checkout calls IPaym…
Short answer: Interface contracts are pure method signatures. Abstract class contracts can contain shared code and fields. Real-world example (ShopNest) Checkout calls IPaymentGateway.Charge() . Razorpay and Stripe adapt…
Short answer: Implementing class must provide implementation once. Explicit interface implementation can resolve ambiguity. interface IDriveable { void Start(); } abstract class Vehicle { public abstract void Start(); }…
Short answer: No, interfaces can only inherit other interfaces. Real-world example (ShopNest) ShopNest has a base PaymentMethod with virtual decimal Fee() . UpiPayment and CardPayment override the fee logic without chang…
Short answer: Yes, abstract classes can implement interfaces partially or fully. Real-world example (ShopNest) Checkout calls IPaymentGateway.Charge() . Razorpay and Stripe adapters implement the same interface, so ShopN…
Short answer: bstract classes? Abstract classes are slightly faster because they use direct method calls. Interfaces may incur slight overhead due to indirect method calls via vtable. Difference is usually negligible in…
Short answer: Abstract classes are slightly faster because they use direct method calls. Interfaces may incur slight overhead due to indirect method calls via vtable. Difference is usually negligible in most applications…
Short answer: Interfaces are preferred for public APIs because they: Allow multiple inheritance Support loose coupling Avoid breaking changes when adding new implementations Abstract classes are better for internal APIs…
Short answer: Interfaces: Adding new members breaks existing implementations unless using default interface methods (C# 8+). Abstract Classes: Can add new methods with implementation without breaking derived classes. Exa…
Short answer: Interfaces support multiple inheritance. Abstract classes do not. Interview Q&A Example code Interfaces support multiple inheritance. Abstract classes do not. Interview Q&A Real-world example (ShopN…
Short answer: Define an interface like IPlugin with a Run() method. Explain a bit more Each plugin implements IPlugin and can be loaded dynamically. interface IPlugin { void Run(); } class PluginA : IPlugin { public void…
Short answer: And interfaces? Use an interface for common operations: IPayment. Use an abstract class for shared behavior like logging. interface IPayment { void Pay(decimal amount); } bstract class PaymentBase : IPaymen…
Short answer: Use an interface for common operations: IPayment. Use an abstract class for shared behavior like logging. interface IPayment { void Pay(decimal amount); } abstract class PaymentBase : IPayment { Example cod…
Short answer: Define a base Notification class or interface. Derive classes like EmailNotification, SMSNotification. abstract class Notification { public abstract void Send(string message); } class EmailNotification : No…
Short answer: SOLID principles are design guidelines that enhance maintainability, flexibility, and scalability of OOP systems. They guide proper use of abstraction, inheritance, encapsulation, and polymorphism. Real-wor…
Short answer: High-level modules should not depend on low-level modules. Both should depend on abstractions. Interfaces allow decoupling and easier testing. interface ILogger { void Log(string message); } Example code cl…
Short answer: ffect it? Derived classes should be replaceable by base class without affecting correctness. Inheritance violating this principle can cause unexpected behavior. Real-world example (ShopNest) ShopNest has a…
Short answer: Derived classes should be replaceable by base class without affecting correctness. Inheritance violating this principle can cause unexpected behavior. Real-world example (ShopNest) ShopNest has a base Payme…
Short answer: Protects internal data by restricting direct access. Ensures sensitive fields are accessed only via methods/properties, preventing misuse. Real-world example (ShopNest) ShopNest’s Order keeps _items private…
Short answer: Use mocking frameworks like Moq or NSubstitute. Provides fake implementations to test dependent classes. var mockLogger = new Mock<ILogger>(); mockLogger.Setup(x => x.Log(It.IsAny<string>()))…
Short answer: Abstract class defines skeleton of algorithm. Derived classes override steps without changing algorithm structure. abstract class DataProcessor { Example code public void Process() { ReadData(); Transform()…
Short answer: When behavior varies significantly. When tight coupling or fragile base class problem may occur. Real-world example (ShopNest) ShopNest has a base PaymentMethod with virtual decimal Fee() . UpiPayment and C…
Short answer: Hard to maintain and understand. Fragile base class problem. Overridden behavior may break subclasses. Real-world example (ShopNest) ShopNest has a base PaymentMethod with virtual decimal Fee() . UpiPayment…
Short answer: Provides flexibility, reduces tight coupling, and avoids deep hierarchies. Real-world example (ShopNest) ShopNest has a base PaymentMethod with virtual decimal Fee() . UpiPayment and CardPayment override th…
Short answer: Minor runtime overhead for virtual calls. Usually negligible; design benefits outweigh performance cost. Real-world example (ShopNest) Checkout calls IPaymentGateway.Charge() . Razorpay and Stripe adapters…
C# OOP C# Programming Tutorial · OOP
Short answer: Both can define contracts for derived classes. Both support polymorphism. Both cannot be instantiated directly. Both can be used with dependency injection.
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Interface contracts are pure method signatures. Abstract class contracts can contain shared code and fields.
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Implementing class must provide implementation once. Explicit interface implementation can resolve ambiguity. interface IDriveable { void Start(); } abstract class Vehicle { public abstract void Start(); } class Car : Vehicle, IDriveable
{
public override void Start() => Console.WriteLine("Car started"); }
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: No, interfaces can only inherit other interfaces.
ShopNest has a base PaymentMethod with virtual decimal Fee(). UpiPayment and CardPayment override the fee logic without changing the checkout caller.
C# OOP C# Programming Tutorial · OOP
Short answer: Yes, abstract classes can implement interfaces partially or fully.
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: bstract classes? Abstract classes are slightly faster because they use direct method calls. Interfaces may incur slight overhead due to indirect method calls via vtable. Difference is usually negligible in most applications.
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Abstract classes are slightly faster because they use direct method calls. Interfaces may incur slight overhead due to indirect method calls via vtable. Difference is usually negligible in most applications.
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Interfaces are preferred for public APIs because they: Allow multiple inheritance Support loose coupling Avoid breaking changes when adding new implementations Abstract classes are better for internal APIs where shared code is required.
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Interfaces: Adding new members breaks existing implementations unless using default interface methods (C# 8+). Abstract Classes: Can add new methods with implementation without breaking derived classes.
Interfaces: Adding new members breaks existing implementations unless using default interface methods (C# 8+). Abstract Classes: Can add new methods with implementation without breaking derived classes.
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Interfaces support multiple inheritance. Abstract classes do not. Interview Q&A
Interfaces support multiple inheritance. Abstract classes do not. Interview Q&A
ShopNest has a base PaymentMethod with virtual decimal Fee(). UpiPayment and CardPayment override the fee logic without changing the checkout caller.
C# OOP C# Programming Tutorial · OOP
Short answer: Define an interface like IPlugin with a Run() method.
Each plugin implements IPlugin and can be loaded dynamically. interface IPlugin { void Run(); } class PluginA : IPlugin { public void Run() => Console.WriteLine("Plugin A running"); } class PluginB : IPlugin { public void Run() => Console.WriteLine("Plugin B running"); } // Usage List<IPlugin> plugins = new List<IPlugin> { new PluginA(), new PluginB() }; foreach (var p in plugins) p.Run();
Define an interface like IPlugin with a Run() method. Each plugin implements IPlugin and can be loaded dynamically. interface IPlugin { void Run(); }
class PluginA : IPlugin { public void Run() => Console.WriteLine("Plugin A running"); } class PluginB : IPlugin { public void Run() => Console.WriteLine("Plugin B running"); } // Usage List<IPlugin> plugins = new List<IPlugin> { new PluginA(), new PluginB() }; foreach (var p in plugins) p.Run();
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: And interfaces? Use an interface for common operations: IPayment. Use an abstract class for shared behavior like logging. interface IPayment { void Pay(decimal amount); } bstract class PaymentBase : IPayment { public abstract void Pay(decimal amount); public void Log(string message) => Console.WriteLine(message); } class CreditCardPayment :… PaymentBase {……… nd interfaces? nd interfaces? Use an interface for common…
operations: IPayment. Use an abstract class for shared behavior like logging. interface IPayment { void Pay(decimal amount); } bstract class PaymentBase : IPayment { public abstract void Pay(decimal amount); public void Log(string message) => Console.WriteLine(message); } class CreditCardPayment : PaymentBase {… nd interfaces? Use an interface for common operations: IPayment. Use an abstract class for shared behavior like logging. interface IPayment { void Pay(decimal amount); } bstract class PaymentBase : IPayment { public abstract void Pay(decimal amount); public void Log(string message) => Console.WriteLine(message); } class… And… public abstract void Pay(decimal amount);
public void Log(string message) => Console.WriteLine(message);
}
class CreditCardPayment : PaymentBase
{
public override void Pay(decimal amount) => Console.WriteLine($"Paid {amount} by Credit Card"); }
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Use an interface for common operations: IPayment. Use an abstract class for shared behavior like logging. interface IPayment { void Pay(decimal amount); } abstract class PaymentBase : IPayment {
public abstract void Pay(decimal amount);
public void Log(string message) => Console.WriteLine(message);
}
class CreditCardPayment : PaymentBase
{
public override void Pay(decimal amount) => Console.WriteLine($"Paid {amount} by Credit Card"); }
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Define a base Notification class or interface. Derive classes like EmailNotification, SMSNotification. abstract class Notification { public abstract void Send(string message); } class EmailNotification : Notification { public override void
Send(string msg) => Console.WriteLine("Email: " + msg); }
class SMSNotification : Notification { public override void
Send(string msg) => Console.WriteLine("SMS: " + msg); }
List<Notification> notifications = new List<Notification> { new EmailNotification(), new SMSNotification() }; foreach (var n in notifications) n.Send("Hello World!");
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: SOLID principles are design guidelines that enhance maintainability, flexibility, and scalability of OOP systems. They guide proper use of abstraction, inheritance, encapsulation, and polymorphism.
ShopNest splits “save order” and “send email” into different services (SRP). The order service depends on IEmailSender (DIP), so unit tests can fake email.
C# OOP C# Programming Tutorial · OOP
Short answer: High-level modules should not depend on low-level modules. Both should depend on abstractions. Interfaces allow decoupling and easier testing. interface ILogger { void Log(string message); }
class FileLogger : ILogger { public void Log(string message) => Console.WriteLine("File: " + message); } class UserService
{
private readonly ILogger _logger;
public UserService(ILogger logger) { _logger = logger; }
}
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: ffect it? Derived classes should be replaceable by base class without affecting correctness. Inheritance violating this principle can cause unexpected behavior.
ShopNest has a base PaymentMethod with virtual decimal Fee(). UpiPayment and CardPayment override the fee logic without changing the checkout caller.
C# OOP C# Programming Tutorial · OOP
Short answer: Derived classes should be replaceable by base class without affecting correctness. Inheritance violating this principle can cause unexpected behavior.
ShopNest has a base PaymentMethod with virtual decimal Fee(). UpiPayment and CardPayment override the fee logic without changing the checkout caller.
C# OOP C# Programming Tutorial · OOP
Short answer: Protects internal data by restricting direct access. Ensures sensitive fields are accessed only via methods/properties, preventing misuse.
ShopNest’s Order keeps _items private and exposes AddItem() so totals stay correct—callers cannot put a negative quantity directly into the list.
C# OOP C# Programming Tutorial · OOP
Short answer: Use mocking frameworks like Moq or NSubstitute. Provides fake implementations to test dependent classes. var mockLogger = new Mock<ILogger>(); mockLogger.Setup(x => x.Log(It.IsAny<string>()));
Use mocking frameworks like Moq or NSubstitute. Provides fake implementations to test dependent classes. var mockLogger = new Mock<ILogger>();
mockLogger.Setup(x => x.Log(It.IsAny<string>()));
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: Abstract class defines skeleton of algorithm. Derived classes override steps without changing algorithm structure. abstract class DataProcessor {
public void Process() { ReadData(); Transform(); Save(); } protected abstract void ReadData(); protected abstract void Transform(); protected void Save() => Console.WriteLine("Data saved");
}
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
C# OOP C# Programming Tutorial · OOP
Short answer: When behavior varies significantly. When tight coupling or fragile base class problem may occur.
ShopNest has a base PaymentMethod with virtual decimal Fee(). UpiPayment and CardPayment override the fee logic without changing the checkout caller.
C# OOP C# Programming Tutorial · OOP
Short answer: Hard to maintain and understand. Fragile base class problem. Overridden behavior may break subclasses.
ShopNest has a base PaymentMethod with virtual decimal Fee(). UpiPayment and CardPayment override the fee logic without changing the checkout caller.
C# OOP C# Programming Tutorial · OOP
Short answer: Provides flexibility, reduces tight coupling, and avoids deep hierarchies.
ShopNest has a base PaymentMethod with virtual decimal Fee(). UpiPayment and CardPayment override the fee logic without changing the checkout caller.
C# OOP C# Programming Tutorial · OOP
Short answer: Minor runtime overhead for virtual calls. Usually negligible; design benefits outweigh performance cost.
Checkout calls IPaymentGateway.Charge(). Razorpay and Stripe adapters implement the same interface, so ShopNest can switch gateways without rewriting the order service.
Install Toolliyo like an app Free
Home-screen access to tutorials, coding practice & career tools — no app store needed.
On iPhone/iPad: tap Share then Add to Home Screen.