Utilizor
Contact Us

Java Methods

Block of code which runs only when it is called.

Examples

Create and Call Method

Defining and calling a simple method.

public class Main {
  static void myMethod() {
    System.out.println("I just got executed!");
  }

  public static void main(String[] args) {
    myMethod();
  }
}

Call Multiple Times

Reusing the method.

public class Main {
  static void myMethod() {
    System.out.println("I just got executed!");
  }

  public static void main(String[] args) {
    myMethod();
    myMethod();
    myMethod();
  }
}

Test Your Knowledge

Java Quiz

No quiz available for this topic yet.