Abstraction is a process of hiding the implementation details and showing only functionality to the user.
Another way, it shows only essential things to the user and hides the internal details, for example, sending SMS where you type the text and send the message. You don’t know the internal processing about the message delivery.
Abstract Class
A class which contains the abstract keyword in its declaration is known as abstract class.
- Abstract classes may or may not contain abstract methods, i.e., methods without body ( public void get(); )
- But, if a class has at least one abstract method, then the class must be declared abstract.
- If a class is declared abstract, it cannot be instantiated.
- To use an abstract class, you have to inherit it from another class, provide implementations to the abstract methods in it.
- If you inherit an abstract class, you have to provide implementations to all the abstract methods in it.

Abstract method in java
An abstract method is a method preceded by an ‘abstract’ keyword without any implementation. An abstract method is declared inside an abstract class.
An abstract method is the one that makes a class incomplete as it doesn’t have an implementation. Hence when we include an abstract method in the class, naturally the class becomes incomplete.
We can use the abstract method by implementing it in a subclass i.e. a class inherits the abstract class and then implements or provides the code for all the abstract methods declared in the abstract class by overriding them.
Thus it becomes compulsory to override the abstract method in the subclass. If the abstract method is not implemented in the subclass as well, then we have to declare the subclass also as “abstract”.
The general declaration of the abstract method is:
abstract void methodName (parameter_list);
While writing the abstract method, we need to remember the following rules:
- A class containing one or more abstract methods is an abstract class.
- Certain other keywords should not be used with the abstract keyword.—[TBD]
Thus, the following combinations are illegal in Java.–[TBD]
- final
- abstract native
- abstract static
- abstract private
- abstract synchronized
- abstract strictfp
example program for abstract class
abstract class MotorBike {
abstract void brake();
}
class SportsBike extends MotorBike {
public void brake() {
System.out.println("SportsBike Brake");
}
}
class MountainBike extends MotorBike {
public void brake() {
System.out.println("MountainBike Brake");
}
}
class Main {
public static void main(String[] args) {
MountainBike m1 = new MountainBike();
m1.brake();
SportsBike s1 = new SportsBike();
s1.brake();
}
}
Key Points to Remember
- We use the
abstractkeyword to create abstract classes and methods. - An abstract method doesn’t have any implementation (method body).
- A class containing abstract methods should also be abstract.
- We cannot create objects of an abstract class.
- To implement features of an abstract class, we inherit subclasses from it and create objects of the subclass.
- A subclass must override all abstract methods of an abstract class. However, if the subclass is declared abstract, it’s not mandatory to override abstract methods.
- We can access the static attributes and methods of an abstract class using the reference of the abstract class.—[TBD]
https://www.javatpoint.com/abstract-class-in-java
https://www.tutorialspoint.com/java/java_abstraction.htm
https://www.programiz.com/java-programming/abstract-classes-methods
Leave a comment