Services Work Learn About Contact
0/10
Lesson 6 of 10

Methods

Methods are functions inside a class. They can accept parameters and return values. Use void when the method returns nothing. Method overloading allows multiple methods with the same name but different parameters.

JAVA
public class Calculator {
  public int add(int a, int b) {
    return a + b;
  }

  public void greet(String name) {
    System.out.println("Hello, " + name);
  }

  public static void main(String[] args) {
    Calculator calc = new Calculator();
    System.out.println(calc.add(3, 4)); // 7
    calc.greet("Ali");
  }
}
🧠

Quick Quiz

Answer correctly to unlock the next lesson.

Support the mission

This learning platform is 100% free: no ads, no tracking, no paywalls. If it helped you learn something useful, you can support future lessons or donate to Doctors Without Borders, which provides emergency medical care in crisis zones worldwide.

🎉

You completed Java!

You finished all 10 lessons and quizzes. You now know the basics of Java.