Static vs Instance Methods
Understand when to use static versus instance members and how calls differ.
Static vs Instance Methods is a free Java Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What does static mean?
Idea: Static members belong to the class. Instance members belong to each object.
Instance members
Instance methods use per-object state. Call them on variables like user.login().
Static members
Static methods/fields are shared. Call them via the class name, e.g., Math.max(a, b).
Choosing static vs instance
Choose instance when behavior depends on object state. Choose static for pure utilities or class-wide counters.
Pitfalls
Avoid using instance fields in a static method. Avoid static where object-specific state is needed.
Demo: static vs instance
Run to see instance calls on objects and static calls via the class. The counter is shared.
public class Main {
public static void main(String[] args) {
// Two Person objects hold different names
Person a = new Person("Ada");
Person b = new Person("Bob");
// Instance method: needs an object
a.greet();
b.greet();
// Static method/field: belong to class Utils
int s = Utils.add(7, 5); // pure function
System.out.println("sum = " + s);
Utils.bumpCounter();
Utils.bumpCounter();
System.out.println("counter = " + Utils.counter); // shared across all
}
static class Person {
private String name;
Person(String name) { this.name = name; }
void greet() {
System.out.println("Hello, " + name + "!");
}
}
static class Utils {
static int counter = 0; // static field (shared)
static int add(int x, int y) { // static method (pure)
return x + y;
}
static void bumpCounter() { // static method (mutates shared)
counter = counter + 1;
}
}
}
Check your understanding
Quick check: Which call works without creating any object first?
Recap
Recap: Static = class-level/shared. Instance = per-object behavior/state.
Frequently asked questions
Is the “Static vs Instance Methods” lesson free?
Yes — the full text of “Static vs Instance Methods” is free to read here on the web, and the Java Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.
What will I learn in “Static vs Instance Methods”?
Understand when to use static versus instance members and how calls differ. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Java Academy?
No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Static vs Instance Methods” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Java Academy lesson?
Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Pass-by-Value in Java
- Static vs Instance Methods
- Method Decomposition & Clean Code