what is abstract method and concrete method in java

"What are Abstract & Concrete Methods in Java?"

By Mark Thompson
AD

In the realm of object-oriented programming, Java provides a powerful feature called method overloading, which allows multiple methods to have the same name but different parameters. Among these methods, two key concepts stand out: abstract methods and concrete methods. Let's delve into the details of these methods, their differences, and their roles in Java programming.

Understanding Methods in Java

Before we dive into abstract and concrete methods, let's briefly recap what methods are in Java. A method is a block of code that performs a specific task. It's defined using the public, private, protected, or default access modifiers, followed by the return type (if any), the method name, and the parameters in parentheses.

Abstract Methods

An abstract method is a method that is declared without a body in the abstract class. It's defined using the abstract keyword and must be implemented by any non-abstract subclasses. Abstract methods provide a blueprint for the subclasses to follow, ensuring that certain methods are implemented in a specific way.

AD
What is Abstraction in Java (with Example) - Scientech Easy
What is Abstraction in Java (with Example) - Scientech Easy
Java: Abstract Class vs Interface Explained
Java: Abstract Class vs Interface Explained
Difference between Method and constructor in Java - Codeforcoding
Difference between Method and constructor in Java - Codeforcoding

Key Characteristics of Abstract Methods

  • An abstract method cannot be accessed directly. It must be overridden in a concrete subclass.
  • Abstract methods are used to achieve abstraction, which is the process of hiding the implementation details and showing only the functionality.
  • Abstract methods are declared with the abstract keyword and do not have a method body (curly braces).
  • Abstract methods can be defined in both abstract and interface classes.

Concrete Methods

Concrete methods, on the other hand, are regular methods that have a body and can be called directly. They provide the actual implementation of the functionality defined by the abstract methods. Concrete methods are defined in non-abstract classes and implement the abstract methods defined in their superclasses or interfaces.

Key Characteristics of Concrete Methods

  • Concrete methods can be accessed directly. They provide the actual implementation of the functionality.
  • Concrete methods can be defined in both concrete classes and interfaces, but they must provide an implementation if defined in an interface.
  • Concrete methods can override the methods of their superclasses or implement the methods of their interfaces.
  • Concrete methods can have a return type (including void) and can throw exceptions.

Abstract vs Concrete Methods: A Comparison

Abstract Methods Concrete Methods
Cannot be accessed directly Can be accessed directly
Provide a blueprint for subclasses Provide the actual implementation
Defined with the abstract keyword and no method body Defined with a method body and can override or implement methods
Can be defined in both abstract and interface classes Can be defined in both concrete and interface classes

In conclusion, abstract methods and concrete methods play crucial roles in Java programming. Abstract methods provide a blueprint for subclasses to follow, while concrete methods provide the actual implementation of that functionality. Understanding the difference between these two types of methods is essential for writing efficient, maintainable, and extensible Java code.

Method Reference In Java 8 [::] - JavaTechOnline
Method Reference In Java 8 [::] - JavaTechOnline
Java Collection Framework: ArrayList Explained Visually
Java Collection Framework: ArrayList Explained Visually
JAVA MAIN METHOD
JAVA MAIN METHOD
Java Cheatsheet for Beginners | Learn Java Basics in One Page
Java Cheatsheet for Beginners | Learn Java Basics in One Page
Java Thread | Multithreading Basics
Java Thread | Multithreading Basics
30 Days of Java – Day 16 | Java Abstraction Explained for Beginners
30 Days of Java – Day 16 | Java Abstraction Explained for Beginners
A Cleaner Way to Study Java Topics
A Cleaner Way to Study Java Topics
Java Abstract Class - Explore the Rules for Using Abstract Class
Java Abstract Class - Explore the Rules for Using Abstract Class
Java for Testers #28 - What is Interface in Java | with Example
Java for Testers #28 - What is Interface in Java | with Example
Method Overloading in Java with Examples - Scientech Easy
Method Overloading in Java with Examples - Scientech Easy
Abstraction in Java - Master the Concept with Real-life Examples
Abstraction in Java - Master the Concept with Real-life Examples
Polymorphism in Java Explained | Method Overloading & Overriding Easy Notes
Polymorphism in Java Explained | Method Overloading & Overriding Easy Notes
Can You Overload or Override Static methods in Java? Example
Can You Overload or Override Static methods in Java? Example
Understanding Object-Oriented Programming in Java
Understanding Object-Oriented Programming in Java
Checkout Method Overriding in Java with Rules and Real-time Examples
Checkout Method Overriding in Java with Rules and Real-time Examples
Java Beginner Cheatsheet ☕ | Learn Java Basics Fast 🚀
Java Beginner Cheatsheet ☕ | Learn Java Basics Fast 🚀
Constructors In Java – Three Different Types Of Constructors
Constructors In Java – Three Different Types Of Constructors
Java Roadmap for Beginners 2026
Java Roadmap for Beginners 2026
Java Exception - Learn with its Types, Methods & Examples - TechVidvan
Java Exception - Learn with its Types, Methods & Examples - TechVidvan
🔥 Java Abstraction Explained! 🚀
🔥 Java Abstraction Explained! 🚀
Complete Java Roadmap for Beginners in 2026
Complete Java Roadmap for Beginners in 2026
Java Generics - An Exclusive Guide on Java Generics
Java Generics - An Exclusive Guide on Java Generics
AD