1.Method in Java:
A method is a block of code that performs a specific task. We can call a method whenever we need to execute that task.
Methods help us avoid repeating the same code multiple times.
Example:
`public class Main {
static void greet() { System.out.println("Hello, Welcome to Java!"); }
public static void main(String[] args) { greet(); }
Enter fullscreen mode
Exit fullscreen mode
}`
Output:
Hello, Welcome to Java!
Explanation
static allows us to call the method using the class without creating an object.
void means the method does not return a value.
greet() is the method name.
System.out.println() displays the message.
greet(); calls the method.
2.Types of Methods in Java
Methods can be categorized in different ways.…