Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ritik62 reputationPosted Aug 18, 2025, 7:52 AM EDT
classes, objects, inheritance, encapsulation, abstraction, and polymorphism
Cynthia SathuragiriRank #937 · 2.2K reputationPosted Aug 19, 2025, 12:33 AM EDT
OOPS = Object-Oriented Programming System
It’s a way of writing programs using objects (like real-life things).
1. Class → A blueprint (like a recipe).
Example: A Car design.
2. Object → A real thing made from the class.
Example: A red Tesla car built using the Car design.
3. Encapsulation → Keep things together (data + actions).
Example: A car’s steering, brakes, and engine are all inside the car.
4. Abstraction → Show only what’s needed, hide details.
Example: You just press the start button; you don’t see how the engine works inside.
5.Inheritance → Pass on features from one class to another.
Example: An ElectricCar is still a Car, but with extra features like a battery.
6.Polymorphism → Same action, different behavior.
Example: The word “start” means different things
Start a Car → engine starts
Start a Bike → bike starts
Ajay BansodeRank #7,443 · 241 reputationPosted Aug 20, 2025, 1:46 PM EDT
OOPs (Object-Oriented Programming System) concepts are the fundamental principles of object-oriented programming, mainly used in languages like C#, Java, Python, C++ etc.
Here are the main OOPs concepts with simple explanation and examples:
1. Class
A class is a blueprint or template for creating objects.
It defines properties (variables/fields) and behaviors (methods/functions).
Example (C#):
public class Car { public string Brand; public int Speed; public void Drive() { Console.WriteLine(Brand + " is driving at " + Speed + " km/h"); } }2. Object
An object is an instance of a class.
It represents a real-world entity.
Example:
Car myCar = new Car(); myCar.Brand = "BMW"; myCar.Speed = 120; myCar.Drive(); // Output: BMW is driving at 120 km/h3. Encapsulation
Wrapping data (fields) and code (methods) into a single unit (class).
We use access modifiers (
private,public,protected) to hide implementation details.Example:
public class BankAccount { private double balance; public void Deposit(double amount) { balance += amount; } public double GetBalance() { return balance; } }Here,
balanceis hidden (private). It can only be accessed via methods.4. Abstraction
Hiding implementation details and showing only essential features.
Achieved using abstract classes or interfaces.
Example:
public abstract class Shape { public abstract void Draw(); // abstract method (no body) } public class Circle : Shape { public override void Draw() { Console.WriteLine("Drawing Circle"); } }5. Inheritance
One class can inherit properties and methods from another.
Promotes code reusability.
Example:
public class Animal { public void Eat() { Console.WriteLine("Eating..."); } } public class Dog : Animal { public void Bark() { Console.WriteLine("Barking..."); } }6. Polymorphism
One name, many forms → the ability of an object to behave differently based on context.
Types:
Compile-time (Overloading) → same method name, different parameters.
Runtime (Overriding) → derived class provides its own implementation.
Example (Method Overloading):
public class MathOperation { public int Add(int a, int b) => a + b; public double Add(double a, double b) => a + b; }Example (Method Overriding):
public class Animal { public virtual void Sound() { Console.WriteLine("Some sound"); } } public class Dog : Animal { public override void Sound() { Console.WriteLine("Bark"); } }Summary of OOPs Concepts:
Class – Blueprint
Object – Instance
Encapsulation – Data hiding
Abstraction – Hiding implementation
Inheritance – Code reusability
Polymorphism – One name, many forms
Sam HobbsRank #107 · 20.5K reputationPosted Aug 26, 2025, 4:37 PM EDT
Object Oriented Programming is not a system, it is a paradigm or model. The term system implies something specific, such as a specific application or other software. People use the acronym OOPS and then other people try to give the acronym meaning but the correct acronym is OOP.
Sandhiya PriyaRank #26 · 43.2K reputationPosted Oct 13, 2025, 3:03 AM EDT
Object-Oriented Programming (OOP) Concepts in C#
OOP (Object-Oriented Programming) is a programming paradigm based on objects that encapsulate data (fields/properties) and behavior (methods). It helps structure code to be more modular, reusable, and maintainable. C# is a fully object-oriented language supporting all core OOP principles.
1. Class and Object
Class: A blueprint/template for creating objects. It defines properties, methods, and events.
Object: An instance of a class.
class Car { public string Model; public void Start() { Console.WriteLine("Car started"); } } Car myCar = new Car(); // object creation myCar.Model = "BMW"; myCar.Start();2. Encapsulation
Definition: Wrapping data and methods inside a class and restricting access to internal details.
Access modifiers:
private,public,protected, etc.class Person { private string name; // hidden public string Name // controlled access { get { return name; } set { name = value; } } }Provides data security and controlled access.
3. Inheritance
Definition: Enables a class to inherit properties and methods from another class.
class Animal { public void Eat() { Console.WriteLine("Eating"); } } class Dog : Animal { public void Bark() { Console.WriteLine("Barking"); } }Dogcan useEat()fromAnimal.Types of Inheritance in C#:
Single Inheritance: One class inherits from one class.
Multilevel Inheritance: Class hierarchy, e.g.,
A -> B -> C.Hierarchical Inheritance: Multiple classes inherit from one base class.
4. Polymorphism
Definition: “Many forms” — the ability to perform the same action in different ways.
a. Compile-Time Polymorphism (Method Overloading)
class Calculator { public int Add(int a, int b) => a + b; public double Add(double a, double b) => a + b; }b. Run-Time Polymorphism (Method Overriding)
class Animal { public virtual void Speak() { Console.WriteLine("Animal sound"); } } class Dog : Animal { public override void Speak() { Console.WriteLine("Bark"); } }5. Abstraction
Definition: Hiding complex details and showing only the essential features.
Achieved using abstract classes and interfaces.
abstract class Shape { public abstract double Area(); } class Circle : Shape { private double radius; public Circle(double r) { radius = r; } public override double Area() => Math.PI * radius * radius; }6. Interfaces
Define a contract that classes must implement.
interface IVehicle { void Drive(); } class Car : IVehicle { public void Drive() { Console.WriteLine("Car is driving"); } }7. Constructors and Destructors
Constructor: Special method called when an object is created.
Destructor: Called when an object is destroyed (rarely used in C# because of garbage collection).
class Car { public string Model; public Car(string model) { Model = model; } }8. Properties
Provide getters and setters for fields.
9. Access Modifiers
Control visibility of classes and members:
public,private,protected,internal,protected internal,private protected.10. Composition
A class can have objects of other classes to reuse functionality.
class Engine { public void Start() { Console.WriteLine("Engine started"); } } class Car { Engine engine = new Engine(); public void StartCar() { engine.Start(); } }Key Advantages of OOP
Reusability: Inheritance allows code reuse.
Encapsulation: Protects data and implementation.
Flexibility: Polymorphism allows different implementations.
Maintainability: Easy to modify and extend.
Modularity: Classes and objects divide code logically.
Jignesh KumarRank #91 · 22.9K reputationPosted Aug 24, 2025, 6:24 AM EDT
Here is my article where I have covered OOPS with a Practical Example
other SOLID principle Articles.
Single Responsibility principle(SRP)
Open/Closed Principle in C#
Liskov Substitution Principle (LSP)