FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses Object-Oriented Programming

CSE

Progress0 / 6 lessons
  1. 1. What a class models, and why OOP was invented
  2. 2. Encapsulation, and why getters exist
  3. 3. Inheritance, and when NOT to use it
  4. 4. Polymorphism, with a runnable example
  5. 5. Abstraction: interfaces versus abstract classes
  6. 6. The SOLID principles in plain English

Courses › Object-Oriented Programming

Abstraction: interfaces versus abstract classes

What each one is for, when to pick which, and a program using both together.

12 min read · Lesson 5 of 6 · Pro

Abstraction is deciding what to leave out

You drive a car without knowing how fuel injection works. The steering wheel, pedals and gear stick are the interface. The engine is the implementation. You can learn to drive one car and drive any car, because every car exposes the same interface.

In code, abstraction means exposing what something does and hiding how it does it. Java gives you two tools for it, and choosing between them confuses almost everyone at first.

An interface is a pure contract

Java
interface Payable {
    long amountPaise();

    default String receipt() {
        return "Amount due: " + amountPaise() + " paise";
    }
}
The rest of this lesson is Pro

The free lessons of Object-Oriented Programming finish what they start — read those first if you have not. This one goes further, and it is part of the paid half.

A pass opens the paid lessons of every course, the mock test papers and the company-wise series. It ends on its own date; nothing renews by itself.

Get a pass — from ₹29 for 7 days

Already bought one? Log in.