Tsallaka zuwa abun ciki
Justice Tech School

Methods

Methods have a return type, name and parameters. static methods belong to the class.

Example
public class Main {
  static int square(int n) { return n * n; }
  static String greet(String n) { return "Hi " + n; }
  public static void main(String[] args) {
    int sq = square(5);
    System.out.println(sq + " " + greet("Ada"));
  }
}

Result

25 Hi Ada

Exercise

Return type for no value.

static  run() {}

Quiz Test

What does void mean?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.