In this article, we will learn about Abstraction in Python.
Start learning Python from scratch for Free.
- Introduction to Programming – Day1
- Introduction to Algorithms – Day 2
- Python operators and variables – Day 3
- Python Control Structures – Day 4
- Functions in Python – Day 5 of Python Series
- How to setup Eclipse IDE for Python? – 6th Day of Python Series
- Collection Data types in Python – 7th Day of Python Series
- Python Debugging and Testing –Python Series-8th day
- Python Built-in Functions, Libraries, and modules – Day 9
- Python regular expressions and lambda functions – Day 10
- Introduction of Python Object-oriented programming(Python Oops) – Day 12
- Python Object and Classes – Day 13
- Encapsulation in Python- Day 14
- Inheritance in Python – Day 15
- Abstraction in Python
Sometimes we want that our class should not be instantiated. Since we are the creator of the class, we know it is abstract in nature and we won’t create an instance for it. But how can another programmer know about it? How can we ensure that some other developer does not end up creating an object of such an abstract class?
So for removing this error we have have to declare a class as abstract class.
We can programmatically declare a class as abstract class.
An Abstract class is a class that can not be instantiated.
Abstract class should never be instantiated, the only way we can use the abstract class is to inherit that class to another class.
- Usually the parent class is an abstract class.
- Abstract classes should not be instantiated.
- If a class has an abstract method, then the class cannot be instantiated.
- Abstract classes are meant to be inherited.
- The child class must implement/override all the abstract methods of the parent class. Else the child class cannot be instantiated.
GIPHY App Key not set. Please check settings