Method modifiers

This page shows a list of the different modifiers that a method can have, as well as examples of how to use them.
A method may contain zero or more modifiers:

public, private, protected
These are all access modifiers which determines from where a method can be called. More about access modifiers in another Java Basics section.

This modifier tells that the method is a class method and belongs to the class rather than an instance of the class.

This is used for multithreaded applications.
If a method is declared synchronized the thread that executes it must obtain a lock on the object that contains the method before it can be executed. Note that this is the case although a class may just have one method that is declared synchronized. If the method is static the lock must be obtained on the class.

A method that is declare abstract does not have a method body, the signature just ends with a semicolon.
If a class has one or more methods that are declared abstract it must itself be declared abstract and cannot be instantiated.

A method declared final cannot be overridden by subclasses.

If a method is declared native it specifies that the method implementation is written in some “native” language such as C and is provided externally to the Java program. Just like the abstract modifier a method declared native does not have a method body, the signature ends with a semicolon.

Here are a few examples of modifiers:

Search for more Java info on this site here:
Custom Search

Any thoughts or questions?