Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Instance members → Belong to each object, require object to access. Static members → Belong to the class itself, shared by all objects. public class Car Example code { public string Model; // Instance publi…
Short answer: By making fields private, external code cannot directly modify sensitive data. Access is controlled via methods or properties, enforcing validation rules. Example: Prevent withdrawing more than the account…
Short answer: Use private fields to store data. Expose controlled access via public properties or methods. Apply validation logic inside these methods/properties. private int age; Example code public int Age { get { retu…
Short answer: Keywords that define visibility of class members. Common C# modifiers: private → accessible only inside the class public → accessible from anywhere protected → accessible in class and derived classes intern…
Short answer: Technically yes, but not recommended. Makes the data vulnerable to invalid modifications. Encapsulation recommends private fields + public properties. Real-world example (ShopNest) Think of ShopNest’s Produ…
Short answer: Encapsulation → Hides internal data, focuses on data protection. Abstraction → Hides implementation details, focuses on simplifying complex systems. Real-world example (ShopNest) ShopNest’s Order keeps _ite…
Short answer: Real-World Example: Bank Account Management public class BankAccount Example code { private string accountNumber; // private field private decimal balance; // private field public string AccountNumber { get…
Short answer: Simplifies complex systems by exposing only relevant functionality. Enhances maintainability, readability, and reusability of code. Reduces dependency on implementation details, making systems more flexible…
Short answer: Using abstract classes or interfaces. Abstract classes can have abstract and non-abstract methods. Interfaces define method signatures only. abstract class Vehicle { public abstract void Start(); } interfac…
Short answer: Classes that cannot be instantiated directly and may contain abstract methods (without implementation). Can have fields, constructors, and concrete methods. abstract class Animal { public abstract void Make…
Short answer: Interfaces define a contract of methods, properties, or events that implementing classes must follow. Interfaces provide full abstraction without any implementation (C# 8+ allows default methods). interface…
Short answer: By exposing method signatures only, interfaces hide the implementation. Allows multiple classes to implement the interface differently, providing flexibility and decoupling. class Bird : IFlyable Example co…
Short answer: No, abstract classes cannot be instantiated directly. Must be inherited by a derived class which implements abstract methods. abstract class Shape { public abstract void Draw(); } // Shape s = new Shape();…
Short answer: Yes, abstract classes can have constructors. Used to initialize fields for derived classes. abstract class Vehicle { Example code public string Brand; public Vehicle(string brand) { Brand = brand; } } class…
Short answer: Yes, abstract classes can have concrete methods with implementation. Allows shared behavior for derived classes. abstract class Animal { Example code public void Sleep() => Console.WriteLine("Sleepi…
Short answer: Hides implementation details, exposing only what is necessary. Users interact with interfaces or abstract methods, not the full system logic. Simplifies testing, maintenance, and understanding of code. Real…
Short answer: Real-World Example: Payment Processing // Abstract class abstract class Payment { public override void Pay(decimal amount) => Console.WriteLine($"Paid {amount:C} using PayPal"); } // Usage Paym…
Short answer: Using the colon (:) symbol. Derived class can access public/protected members of the base class. class Vehicle { public void Start() => Console.WriteLine("Start"); } Example code class Car : Ve…
Short answer: No, C# does not support multiple class inheritance to avoid ambiguity. Real-world example (ShopNest) ShopNest has a base PaymentMethod with virtual decimal Fee() . UpiPayment and CardPayment override the fe…
Short answer: Common functionality is implemented in base class. Derived classes reuse the code without duplicating it, reducing maintenance effort. Real-world example (ShopNest) ShopNest has a base PaymentMethod with vi…
Short answer: No, private members are hidden from derived classes. Can access protected, internal, or public members. class Vehicle { private int id; protected string model; } Example code class Car : Vehicle { /* cannot…
Short answer: Yes, constructors can have multiple signatures in the same class. class Car Example code { public Car() { } public Car(string model) { } } Real-world example (ShopNest) Think of ShopNest’s Product , Cart ,…
Short answer: No, constructors cannot be inherited or overridden. Base class constructor can be called using : base(), but cannot be overridden. Real-world example (ShopNest) Think of ShopNest’s Product , Cart , and Orde…
Short answer: How is polymorphism implemented in C#? is a common interview topic in C# OOP. Give a clear definition, then one concrete example. Real-world example (ShopNest) Checkout calls IPaymentGateway.Charge() . Razo…
Short answer: abstract class Shape { public abstract void Draw(); } class Circle : Shape { public override void Draw() => Console.WriteLine("Drawing Circle"); } class Rectangle : Shape { public override void…
C# OOP C# Programming Tutorial · OOP
Short answer: Instance members → Belong to each object, require object to access. Static members → Belong to the class itself, shared by all objects. public class Car
{
public string Model; // Instance
public static int Count; // Static
}
Think of ShopNest’s Product, Cart, and Order classes: each object holds data + behavior, so pricing rules stay next to the data they use.
C# OOP C# Programming Tutorial · OOP
Short answer: By making fields private, external code cannot directly modify sensitive data. Access is controlled via methods or properties, enforcing validation rules. Example: Prevent withdrawing more than the account balance: public void Withdraw(decimal amount)
{
if (amount <= balance) balance -= amount; else throw new InvalidOperationException("Insufficient balance"); }
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 private fields to store data. Expose controlled access via public properties or methods. Apply validation logic inside these methods/properties. private int age;
public int Age
{ get { return age; } set { if (value > 0) age = value; }
}
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: Keywords that define visibility of class members. Common C# modifiers: private → accessible only inside the class public → accessible from anywhere protected → accessible in class and derived classes internal → accessible within the same assembly protected internal → accessible in derived classes or same assembly
Think of ShopNest’s Product, Cart, and Order classes: each object holds data + behavior, so pricing rules stay next to the data they use.
C# OOP C# Programming Tutorial · OOP
Short answer: Technically yes, but not recommended. Makes the data vulnerable to invalid modifications. Encapsulation recommends private fields + public properties.
Think of ShopNest’s Product, Cart, and Order classes: each object holds data + behavior, so pricing rules stay next to the data they use.
C# OOP C# Programming Tutorial · OOP
Short answer: Encapsulation → Hides internal data, focuses on data protection. Abstraction → Hides implementation details, focuses on simplifying complex systems.
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: Real-World Example: Bank Account Management public class BankAccount
{
private string accountNumber; // private field
private decimal balance; // private field
public string AccountNumber { get { return accountNumber; } } // read-only public decimal Balance { get { return balance; } } // read-only public BankAccount(string accNum, decimal initialBalance)
{
accountNumber = accNum; balance = initialBalance >= 0 ? initialBalance : throw new ArgumentException("Invalid balance"); }
public void Deposit(decimal amount)
{
if(amount > 0) balance += amount; else throw new ArgumentException("Deposit must be positive"); }
public void Withdraw(decimal amount)
{
if(amount > 0 && amount <= balance) balance -= amount; else throw new InvalidOperationException("Insufficient balance"); }
} // Usage BankAccount myAccount = new BankAccount("ACC123", 1000); myAccount.Deposit(500); // Balance becomes 1500 myAccount.Withdraw(200); // Balance becomes 1300 Console.WriteLine($"Account: {myAccount.AccountNumber}, Balance: {myAccount.Balance}"); Explanation: accountNumber and balance are private, protecting sensitive data. Controlled access via methods ensures data integrity. Demonstrates real-world encapsulation in action.
C# OOP C# Programming Tutorial · OOP
Short answer: Simplifies complex systems by exposing only relevant functionality. Enhances maintainability, readability, and reusability of code. Reduces dependency on implementation details, making systems more flexible.
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: Using abstract classes or interfaces. Abstract classes can have abstract and non-abstract methods. Interfaces define method signatures only. abstract class Vehicle { public abstract void Start(); } interface IDriveable { void Drive(); }
Using abstract classes or interfaces. Abstract classes can have abstract and non-abstract methods. Interfaces define method signatures only. abstract class Vehicle {
public abstract void Start();
}
interface IDriveable
{ void Drive(); }
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: Classes that cannot be instantiated directly and may contain abstract methods (without implementation). Can have fields, constructors, and concrete methods. abstract class Animal { public abstract void MakeSound(); public void Sleep() => Console.WriteLine("Sleeping"); }
Classes that cannot be instantiated directly and may contain abstract methods (without implementation). Can have fields, constructors, and concrete methods. abstract class Animal {
public abstract void MakeSound();
public void Sleep() => Console.WriteLine("Sleeping");
}
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 define a contract of methods, properties, or events that implementing classes must follow. Interfaces provide full abstraction without any implementation (C# 8+ allows default methods). interface IFlyable
{ void Fly(); }
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: By exposing method signatures only, interfaces hide the implementation. Allows multiple classes to implement the interface differently, providing flexibility and decoupling. class Bird : IFlyable
{
public void Fly() => Console.WriteLine("Bird is flying");
}
class Airplane : IFlyable
{
public void Fly() => Console.WriteLine("Airplane is flying");
}
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, abstract classes cannot be instantiated directly. Must be inherited by a derived class which implements abstract methods. abstract class Shape { public abstract void Draw(); } // Shape s = new Shape(); // Not allowed
class Circle : Shape { public override void Draw() => Console.WriteLine("Circle"); }
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: Yes, abstract classes can have constructors. Used to initialize fields for derived classes. abstract class Vehicle {
public string Brand;
public Vehicle(string brand) { Brand = brand; }
}
class Car : Vehicle
{
public Car(string brand) : base(brand) { }
}
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: Yes, abstract classes can have concrete methods with implementation. Allows shared behavior for derived classes. abstract class Animal {
public void Sleep() => Console.WriteLine("Sleeping");
public abstract void MakeSound();
}
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: Hides implementation details, exposing only what is necessary. Users interact with interfaces or abstract methods, not the full system logic. Simplifies testing, maintenance, and understanding of code.
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: Real-World Example: Payment Processing // Abstract class abstract class Payment { public override void Pay(decimal amount) => Console.WriteLine($"Paid {amount:C} using PayPal"); } // Usage Payment payment1 = new CreditCardPayment(); payment1.Pay(500); payment1.ShowReceipt(500); Payment payment2 = new PayPalPayment(); payment2.Pay(300); payment2.ShowReceipt(300); Explanation: Payment defines what a payment should do…
(abstract method Pay). Derived classes (CreditCardPayment, PayPalPayment) define how payment is made. Users interact only with the abstract interface, not the internal logic.
public abstract void Pay(decimal amount);
public void ShowReceipt(decimal amount) => Console.WriteLine($"Paid: {amount:C}"); } // Derived classes implement abstraction class CreditCardPayment : Payment
{
public override void Pay(decimal amount) => Console.WriteLine($"Paid {amount:C} using Credit Card"); }
class PayPalPayment : Payment
{
C# OOP C# Programming Tutorial · OOP
Short answer: Using the colon (:) symbol. Derived class can access public/protected members of the base class. class Vehicle { public void Start() => Console.WriteLine("Start"); }
class Car : Vehicle { }
Car myCar = new Car(); myCar.Start(); // Inherited method
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: No, C# does not support multiple class inheritance to avoid ambiguity.
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: Common functionality is implemented in base class. Derived classes reuse the code without duplicating it, reducing maintenance effort.
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: No, private members are hidden from derived classes. Can access protected, internal, or public members. class Vehicle { private int id; protected string model; }
class Car : Vehicle { /* cannot access id, can access model */ }
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, constructors can have multiple signatures in the same class. class Car
{
public Car() { }
public Car(string model) { }
}
Think of ShopNest’s Product, Cart, and Order classes: each object holds data + behavior, so pricing rules stay next to the data they use.
C# OOP C# Programming Tutorial · OOP
Short answer: No, constructors cannot be inherited or overridden. Base class constructor can be called using : base(), but cannot be overridden.
Think of ShopNest’s Product, Cart, and Order classes: each object holds data + behavior, so pricing rules stay next to the data they use.
C# OOP C# Programming Tutorial · OOP
Short answer: How is polymorphism implemented in C#? is a common interview topic in C# OOP. Give a clear definition, then one concrete example.
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 Shape { public abstract void Draw(); } class Circle : Shape { public override void Draw() => Console.WriteLine("Drawing Circle"); } class Rectangle : Shape { public override void Draw() => Console.WriteLine("Drawing Rectangle"); } Shape s1 = new Circle();
Shape s2 = new Rectangle(); s1.Draw(); // Circle's Draw s2.Draw(); // Rectangle's Draw
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.