Card 02/ 10

ExampleDifficulty: Beginner1 min

Reading a Method Signature From Left to Right

One line from a real class, with five separate decisions packed into it. Read left to right and each word answers one question.

java
public static int add(int a, int b) {
    return a + b;
}
Each part of the signature, and the question it answers
PartQuestion it answers
publicWho may call it
staticDoes it belong to the class rather than to one object
intWhat does it hand back
addWhat do callers write
(int a, int b)What must callers supply, and in what order

Two of those are worth reading carefully. The return type is the promise: declaring int means every path through the body has to end in a return of an int, and the compiler checks every path. Declaring void means the opposite promise — the method produces nothing, and return someValue; inside it will not compile.

What to notice: the parameter list is the only part that decides which method a call matches, and the return type is not part of that decision at all.