Topic 1.10 Notes – Calling Class Methods
What Class Methods Are
A class method is a method declared with the keyword static.
public static int square(int x) {
return x * x;
}
That static keyword changes everything.
- The method belongs to the class, not to any specific object.
- You do not need to create an object to use it.
- It does not have access to
this. - It can directly access only:
- Other static methods
- static variables
Think of it this way. On the right are utility-style classes whose methods are labeled static. On the left are regular classes where methods belong to individual objects.

Class-level (static) methods vs. instance methods
Static methods live at the class level. Instance methods live inside objects created from that class.
If a method doesn’t use instance variables or instance methods, it usually should be static.
How to Call Static Methods
Calling from Outside the Class
The standard format:
ClassName.methodName(arguments);
Examples you should instantly recognize:
Math.sqrt(36);
Math.pow(3, 2);
Integer.parseInt("42");
Notice:
- No object is created.
- The class name comes first.
- The dot operator connects the class to its method.
If you forget the class name outside the defining class, it won’t compile.
Calling from Inside the Same Class
Inside the class where the static method is defined, both of these work:
square(5); // preferred
Calculator.square(5); // also valid
The class name is optional because you’re already “inside” the class.
On tests, they love checking this distinction:
- Outside → class name required
- Inside → class name optional
Static vs Instance Methods
You need to quickly spot which type a call requires.
Here’s the clean comparison:
| Feature | Instance Method | Static Method |
|---|---|---|
| Belongs to | Object | Class |
| Called with | object.method() |
ClassName.method() |
| Access to instance variables | Yes | No (unless given an object) |
Has this |
Yes | No |
Example:
public class Counter {
private int count = 0;
public void increment() { // instance method
count++;
}
public static int triple(int x) { // static method
return x * 3;
}
}
Valid calls:
Counter.triple(4); // correct
Counter c = new Counter();
c.increment(); // correct
Invalid:
Counter.increment(); // errorWhat Static Methods Can and Cannot Do
Inside a static method:
✔️ You can:
- Use parameters
- Call other static methods
- Create objects
- Call instance methods using an object reference
❌ You cannot:
- Use instance variables directly
- Call instance methods without an object
Classic compile error:
non-static variable cannot be referenced from a static context
That means you tried to use object-level data inside a class-level method.
Determining the Result of a Static Method Call
When tracing:
- Evaluate arguments first
- Match arguments to parameters
- Execute the method body
- Return the value (if non-void)
Example:
int value = Math.abs(-8) + 2;
Step through it:
Math.abs(-8) → 8
8 + 2 → 10
value = 10
They often nest calls:
int result = Math.max(5, Math.min(9, 3));
Work inside-out:
Math.min(9, 3) → 3
Math.max(5, 3) → 5
On multiple choice, mistakes usually happen because students rush argument evaluation.
Why main Is Static
public static void main(String[] args)
main must be static because the program starts running before any objects exist. The JVM calls it using the class name.
No object → must be static.