I have seen "divergent" definitions of the terms abstract method, concrete method and default method in some StackOverflow answers.
What are the real definitions, as given by the Java Language Specification? Please include the relevant supporting JLS references in your answer.
An abstract method is declared by abstract keyword, such methods cannot have a body. If a class contains an abstract method, then it also needs to be abstract. Concrete Class: A concrete class in Java is a type of subclass, which implements all the abstract method of its super abstract class which it extends to.
The abstract class can have a state, and its methods can access the implementation's state. Although default methods are allowed in an interface, they can't access the implementation's state.
A concrete method means, the method has complete definition but it can be overridden in the inherited class. If we make this method "final" then it can not be overriden. Declaring a method or class "final" means its implementation is complete.
Abstract methods are those types of methods that don't require implementation for its declaration. These methods don't have a body which means no implementation. A few properties of an abstract method are: An abstract method in Java is declared through the keyword “abstract”.
The links / section numbers below are taken from the Java 11 version of the Java Language Specification.
According to JLS 8.4.3.1:
"An
abstract
method declaration introduces the method as a member, providing its signature (§8.4.2), result (§8.4.5), and throws clause if any (§8.4.6), but does not provide an implementation (§8.4.7). A method that is notabstract
may be referred to as a concrete method."
According to JLS 9.4:
"A default method is an instance method declared in an interface with the
default
modifier. Its body is always represented by a block, which provides a default implementation for any class that implements the interface without overriding the method. Default methods are distinct from concrete methods (§8.4.3.1), which are declared in classes, and from private interface methods, which are neither inherited nor overridden."
So according to this taxonomy there are really 4 types of methods:
Note that JLS 8.4.3.1 makes no mention of final
or static
in the distinction between abstract and concrete methods.
These modifiers cannot be used with the abstract
keyword. This implies that methods that are static
or final
must be concrete methods. This reinforces the 8.4.3.1 definition of a concrete method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With