How to declare and invoke methods in Java?
How to declare and invoke methods in Java?
247
21-Mar-2025
Updated on 21-Mar-2025
Amrith Chandran
21-Mar-2025Method in Java
A method in Java is a block of code that performs a specific task. It improves the reusability and modularity of the code.
Declaring a Method
The below syntax is for declaring a method in java,
Components of a method declaration:
void.Example
Invoking (Calling) a Method
To execute a method, we need to call it using its name.
Syntax
If the method is
statictype then call it using its class nameExample
Ouput
Also, Read: Types of Methods in Java