Abstract Method in Java with Examples

Sometimes, in the case of inheritance, we only require specific method declaration in super-classes. These methods are defined in the child class(es) according to the requirement. In such cases, we declare abstract methods in the abstract class. A method that does not have its implementation or body is known as an abstract method in Java. An abstract method in Java is declared inside an abstract class.
An abstract class may or may not contain an abstract method in java. Abstract methods, on the other hand, must be declared inside an abstract class and do not have a default implementation. Subclasses that extend an abstract class must either provide an implementation for all of its abstract methods or be declared as abstract themselves.
Java Abstract Method
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Syntax for Abstract Method in Java
The basic syntax of the abstract method in Java is:
Example
As we can see, no definition of the method is present (the method ends with a semicolon (;)).
Important Points for Java Abstract Method
The abstract method in Java is also known as subclasses responsibility because they have no implementation specified in the super-class. There are some essential points for abstract method in Java, which are listed below as -
- An abstract method is declared inside an abstract class, and the class that extends the abstract class is called the concrete class.
- A concrete class must contain the definition of the inherited abstract method.
- If a class has an abstract method, then the class should be declared abstract as well.
- Abstract methods in Java are not implemented; they only have a method signature (declaration).
- An abstract class may or may not contain abstract methods in Java.
- Abstract methods end with a semicolon rather than curly brackets or {}.
- If a concrete or regular class extends an abstract class, then the child class must implement all the abstract methods of the parent abstract class. Otherwise, the child class must be declared abstract as well.
Turn Learning into Career Growth
Example of Abstract Method in Java
Output:
Explanation:
In the above example, we have an Animal class, which is an abstract class containing abstract methods. Every animal has different specifications, like different legs, eyes, and color, but all animals belong to a single kingdom, so we can declare an Animal class as an abstract class. The child classes like Monkey, Camel, Lion, etc. can declare the abstract methods of the Animal class as per their requirements.
Abstract Method in Interface
As we know, abstract methods are declared inside abstract classes, but we can also declare abstract methods inside an interface because all interface methods are public abstract by default.
Let us take an example to understand how abstract methods work with interfaces in Java.
Output:
Conclusion
- A method without implementation or body is known as an abstract method in Java.
- If a class has an abstract method, then the class should be declared abstract as well.
- Abstract methods in Java do not have an implementation; abstract methods only have a method signature (declaration).
- An abstract class in Java may or may not contain abstract methods.
- Abstract methods ends with a semicolon rather than curly brackets or {}.