In Object-Oriented Programming, abstraction is the process of hiding unnecessary details and showing only essential information.
To implement abstraction in real code, we use:
- Abstract Classes, and
- Interfaces
These tools help create structured, flexible, and reusable code where we define what to do, but let subclasses decide how to do it.

Abstract Classes
An abstract class is a class that cannot be instantiated directly.
It serves as a blueprint for other classes.
Definition:
An abstract class contains one or more abstract methods methods that are declared but not implemented.
Example (C++ – Using Pure Virtual Function):
#include <iostream>
using namespace std;
class Shape {
public:
// Pure virtual function (no definition)
virtual void draw() = 0;
void message() {
cout << "This is a shape." << endl;
}
};
class Circle : public Shape {
public:
void draw() override {
cout << "Drawing a Circle." << endl;
}
};
int main() {
// Shape s; // ❌ Cannot create object of abstract class
Circle c;
c.draw();
c.message();
}
Explanation:
Shapeis an abstract class because it has a pure virtual functiondraw().- Any class inheriting it must override
draw()or else it also becomes abstract.
Example (Java – Using Abstract Class):
abstract class Shape {
abstract void draw(); // Abstract method
void message() {
System.out.println("This is a shape.");
}
}
class Circle extends Shape {
void draw() {
System.out.println("Drawing a Circle.");
}
}
public class Main {
public static void main(String[] args) {
// Shape s = new Shape(); // ❌ Not allowed
Circle c = new Circle();
c.draw();
c.message();
}
}
Java follows the same principle you can define both abstract and concrete methods inside an abstract class.
As we are discussing Abstract Classes and Interfaces in oop, Polymorphism is also a main pillar of oop. You can explore Polymorphism: Compile-time and Run-time.
Partial Abstraction
An abstract class can have:
- Abstract methods → no implementation (to be defined by child)
- Concrete methods → already implemented
This is called partial abstraction because it hides some details but not all.
Example:
In the above example, draw() is abstract, but message() is concrete.
Hence, Shape is partially abstract.
Interfaces
An interface is like a fully abstract class.
It only defines what must be done, not how to do it.
Example (Java Interface):
interface Drawable {
void draw(); // Always abstract
}
class Circle implements Drawable {
public void draw() {
System.out.println("Drawing a Circle.");
}
}
public class Main {
public static void main(String[] args) {
Drawable d = new Circle();
d.draw();
}
}
Key Points:
- All methods in an interface are public and abstract by default.
- A class must use the keyword
implementsto use an interface. - Interfaces achieve 100% abstraction.
Example (C++ – Using Pure Virtual Functions):
#include <iostream>
using namespace std;
class Drawable {
public:
virtual void draw() = 0; // Pure virtual function
};
class Circle : public Drawable {
public:
void draw() override {
cout << "Drawing a Circle." << endl;
}
};
int main() {
Drawable* d = new Circle();
d->draw();
delete d;
}
In C++, an interface is created by defining a class with only pure virtual functions.
Real-World Applications
| Scenario | Abstraction Type | Example |
|---|---|---|
| Payment Systems | Interface | Payment interface → PayPal, Stripe classes implement it |
| Shapes in Graphics | Abstract Class | Shape base class → Circle, Rectangle subclasses |
| Vehicles | Abstract Class | Vehicle → Car, Bike |
| Devices | Interface | Connectable → BluetoothDevice, WiFiDevice |
Abstract Class vs Interface
| Feature | Abstract Class | Interface |
|---|---|---|
| Methods | Can have both abstract and concrete | Only abstract methods (in classic Java) |
| Variables | Can have instance variables | Only constants (final static) |
| Multiple Inheritance | Not supported | Supported via multiple interfaces |
| Abstraction Type | Partial | Full |
| Use Case | When base class shares logic | When only behavior needs to be defined |
Summary of Lecture 11
| Concept | Description | Example |
|---|---|---|
| Abstract Class | Blueprint for subclasses | abstract class Shape |
| Abstract Method | Declared, not defined | void draw(); |
| Interface | 100% abstraction | interface Drawable |
| Pure Virtual Function | Abstract method in C++ | virtual void draw() = 0; |
Positive Thought for Students
Abstraction is wisdom knowing what to show, what to hide, and how to keep things simple.
People also ask:
An abstract class provides a base structure for subclasses and allows both defined and undefined (abstract) methods.
An interface contains only method declarations, while an abstract class can have both declarations and implementations.
Yes, a class can implement multiple interfaces to achieve multiple inheritance in a flexible and modular way.




