What students Say?
Here are the stdudents...
Abstraction means showing only what is necessary and hiding how it is done.
“Kya kaam ho raha hai dikhana, kaise ho raha hai chupana.”When you press the accelerator, the car moves. You don’t need to know the complex engine logic or fuel injection process. You just use the functionality. That is abstraction.
It is very important to understand the difference between these two core OOPs concepts.
| Encapsulation | Abstraction |
|---|---|
| Data hiding | Logic hiding |
| HOW data is protected | WHAT methods are available |
| Uses access modifiers (private/public) | Uses abstract classes and methods |
| Example: private variables (__marks) | Example: abstract methods |
Python provides the abc module (Abstract Base Classes) to implement abstraction.
from abc import ABC, abstractmethod
class Animal(ABC): # Abstract Class
@abstractmethod
def sound(self): # Abstract Method
pass
If a child class inherits from an abstract class, it must define all abstract methods, or Python will throw an error.
class Dog(Animal):
def sound(self):
print("Dog barks")
d = Dog()
d.sound() # Output: Dog barks
Commonly asked in interviews and exams to demonstrate functionality hiding.
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Square(Shape):
def area(self):
print("Area = side × side")
s = Square()
s.area() # Output: Area = side × side
Summary of core Abstraction concepts for quick reference.
| Concept | Meaning |
|---|---|
| Abstraction | Process of hiding implementation details. |
| ABC | The module used to create abstract classes. |
| @abstractmethod | Decorator used to define a method without logic. |
| Object Creation | Not allowed for abstract classes (e.g., a = Animal() -> ERROR). |
Definition: Abstraction is the process of hiding implementation details and showing only essential features to the user.
Here are the stdudents...
Empower your tech dreams with us. Get in touch!




