Working with Methods and Encapsulation
Declaring methods
Every method declares a return type or void; modifier order is free. Overloading means the same name with a different parameter list (count, types, or order). Return type, parameter names, and thrown exceptions do not participate in overloading. A varargs parameter (int... nums) must be last, accepts an array, and is treated as an array inside the method.
How arguments are passed
Java is strictly pass-by-value. For primitives the value is copied, so changes are invisible to the caller. For objects a copy of the reference is passed: mutating the object's state is visible, but reassigning the parameter is not.
Access control
private (declaring class only), default/package-private (same package), protected (same package plus subclasses), public (everywhere). Locals cannot take access modifiers. Notably, a class can read the private members of other instances of the same class, which makes equals implementations legal.
Encapsulation and constructors
Encapsulation means private fields with public getters/setters, with validation placed in the setter. Constructors have the class name and no return type - adding one makes the method ordinary. If you declare any constructor, the compiler stops generating the default no-argument constructor. this(...) chains to another constructor and must be the first statement.
Traps
A method with the same name but a different return type is a compile error, not an overload. static methods cannot use this or access instance fields directly. A getter that returns a mutable object reference breaks encapsulation unless it returns a copy.
Rule of thumb
Overloading changes "what you pass in"; overriding changes "what happens at runtime."
Worked example
void m(int x) and int m(int x) in one class do not compile. void m(int x) and void m(long x) are valid overloads; calling m(5) selects the int version.