Static Members and Initialization
LockedLesson 11 of 60 · OOP · Medium
Mastery0% of 85%
Up next: Variables and Primitive Types (~7 min) →Finish these first:Classes and Objects →Or pass the tests below to unlock it now.
1
The big idea
static members belong to the class, not instances. Use static final for constants.
Think of it like this: Think of a Class as a cookie cutter (the blueprint) and each Object as an individual cookie stamped from it — each cookie can have its own frosting (state) while sharing the same shape (methods).
Key words (tap to learn):
2
Read the lesson
static members belong to the class, not instances. Use static final for constants. Static nested classes don't hold an outer instance.
class Ids {
private static int next = 1;
static int nextId() { return next++; }
}
3
Quick check
Before writing code: What should `(Solution.nextId() + Solution.nextId() * 10)` return when your implementation of Static Members and Initialization is working?
4
2 sample tests, 1 hiddenYour challenge
Write static int nextId() returning 1, 2, 3, ... on successive calls.
Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
See how Java compares side-by-side with Python.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Static Members and Initialization.
Mastery0%
Learn this first
- Classes and ObjectsNot yet
Opens up next
This is the last lesson in this branch.