Tsallaka zuwa abun ciki
Justice Tech School

Static Methods and Utility Classes

static methods belong to the class and are called without an object, like Math.max. Utility classes group helpers and use a private constructor.

Example
public class Main {
    static final class Texts {
        private Texts() {}
        static String initials(String name) {
            StringBuilder sb = new StringBuilder();
            for (String p : name.split(" ")) sb.append(Character.toUpperCase(p.charAt(0)));
            return sb.toString();
        }
    }
    public static void main(String[] args) {
        System.out.println(Texts.initials("ada lovelace") + " " + Math.max(3, 9));
    }
}

Result

AL 9

Exercise

Belongs to the class.

 int count;

Quiz Test

How do you call a static method?

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