Menu

Java - Methods & Method Overloading
📰

Java - Methods & Method Overloading

DEV Community: java·Gowtham·19 days ago
#91PRw6ub
#devtojava#devto#dev#method#static
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.