what is concrete method in java

"What is the Concrete Method in Java?"

By Steven Lee
AD

The term "concrete method" in Java might seem like a contradiction, as Java is known for its abstract and interface-based programming. However, in the context of Java, a concrete method is a method that is not abstract and provides a complete implementation. It's the opposite of an abstract method, which is declared but not implemented in an abstract class or interface. Let's delve into the world of concrete methods in Java, exploring their role, how to create them, and their significance in object-oriented programming.

Understanding Concrete Methods

A concrete method in Java is a method that contains a method body, i.e., it has both a declaration and an implementation. It can be defined in any class, including abstract classes and interfaces (since Java 8). Concrete methods are the building blocks of any Java application, as they define the actual behavior of a class or interface.

Concrete Methods vs Abstract Methods

To understand concrete methods better, let's compare them with abstract methods:

AD
Difference between Method and Constructor in Java and OOP? Example
Difference between Method and Constructor in Java and OOP? Example
java interview questions
java interview questions
Java Methods - A Complete Guide to Master the Concept
Java Methods - A Complete Guide to Master the Concept
  • Concrete Method: Has a method body. It provides a complete implementation. It can be defined in any class or interface (since Java 8).
  • Abstract Method: Has no method body. It only has a declaration. It must be defined in an abstract class or interface. It provides a contract for the subclasses or implementing classes.

Creating Concrete Methods

Creating a concrete method in Java is straightforward. Here's a simple example:

```java public class Dog { public void bark() { System.out.println("Woof!"); } } ```

In this example, the `bark()` method is a concrete method. It has a declaration and an implementation. When an object of the `Dog` class calls this method, it will print "Woof!".

Java Program Structure Explained ☕ | Beginner-Friendly Guide
Java Program Structure Explained ☕ | Beginner-Friendly Guide
Steps to becoming a java pro
Steps to becoming a java pro
Java Constructor - Get One Step Closer to Become a Java Expert
Java Constructor - Get One Step Closer to Become a Java Expert

Concrete Methods in Interfaces (Java 8 and Later)

Before Java 8, interfaces could only contain abstract methods. However, with the introduction of default methods in Java 8, interfaces can now have concrete methods with implementations. Here's an example:

```java public interface Greetable { default void greet() { System.out.println("Hello, how are you?"); } } ```

In this case, the `greet()` method is a concrete method defined in an interface. Any class that implements this interface can use this method as is, or override it if needed.

AD

The Role of Concrete Methods in Inheritance and Polymorphism

Concrete methods play a crucial role in inheritance and polymorphism. When a subclass inherits from a superclass, it can override the superclass's concrete methods to provide its own implementation. This is the essence of polymorphism, where an object can behave differently based on its type. Here's an example:

A Cleaner Way to Study Java Topics
A Cleaner Way to Study Java Topics
Top 50 Java Projects
Top 50 Java Projects
Best Java Training in Chennai|Java Course Chennai - Enroll Now
Best Java Training in Chennai|Java Course Chennai - Enroll Now
Method Overloading And Method Overriding In Java
Method Overloading And Method Overriding In Java
a poster with different types of writing and numbers on it, including the words'jwa beginner notes '
a poster with different types of writing and numbers on it, including the words'jwa beginner notes '
Method Reference In Java 8 [::] - JavaTechOnline
Method Reference In Java 8 [::] - JavaTechOnline
```java public class Animal { public void makeSound() { System.out.println("The animal makes a sound"); } } public class Cat extends Animal { @Override public void makeSound() { System.out.println("Meow!"); } } ```

In this example, the `Animal` class has a concrete method `makeSound()`. The `Cat` class overrides this method to provide its own implementation. When a `Cat` object calls `makeSound()`, it will print "Meow!".

Concrete methods are fundamental to Java programming. They define the behavior of classes and interfaces, and they are the key to achieving polymorphism and code reusability. Understanding concrete methods is crucial for any Java developer, as it forms the basis of object-oriented programming in Java.

AD
Structure of a Java Program + Hello World Example | Java Programming Basics 💻
Structure of a Java Program + Hello World Example | Java Programming Basics 💻
Java: Abstract Class vs Interface Explained
Java: Abstract Class vs Interface Explained
Java Method - Declaring and Calling Method with Example - DataFlair
Java Method - Declaring and Calling Method with Example - DataFlair
🚀 5 Essential Java Methods Every Developer Should Know! 💻
🚀 5 Essential Java Methods Every Developer Should Know! 💻
Java Roadmap for Beginners 2026
Java Roadmap for Beginners 2026
Java for Testers #28 - What is Interface in Java | with Example
Java for Testers #28 - What is Interface in Java | with Example
Top 5 Java Projects for Beginners
Top 5 Java Projects for Beginners
Web development programming coding for beginners
Web development programming coding for beginners
Java Interview Questions Part 2 (Advanced for Freshers)
Java Interview Questions Part 2 (Advanced for Freshers)
Complete Java Roadmap for Beginners in 2026
Complete Java Roadmap for Beginners in 2026
Java RoadMap
Java RoadMap
Constructor in Java Explained | Default & Parameterized Constructor
Constructor in Java Explained | Default & Parameterized Constructor
Java Generics - An Exclusive Guide on Java Generics
Java Generics - An Exclusive Guide on Java Generics
Java String Methods
Java String Methods
AD