Methods in Java

From the Java cheat sheet · Methods · verified Jul 2026

Methods

Parameters, return types, overloading, and varargs.

java
// Quick Reference
returnType name(params) { ... return value; }
void greet(String n) { ... }        // no return value
int add(int... nums) { ... }        // varargs
💡 Overloading distinguishes methods by parameter types, not by return type.
⚡ Varargs (int...) must be the last parameter and behaves like an array inside.
📌 static methods belong to the class (Util.triple); instance methods need an object.
🟢 Java passes arguments by value - object references are copied, not the objects.
methodsvarargs
Back to the full Java cheat sheet