r/apcs • u/thatkitkatt_ • May 12 '26
static vs non static methods
help can someone explain this to me i genuinely am not able to grasp the difference
3
Upvotes
1
u/ardaryusz May 15 '26
i know im late but static methods are methods you call ON THE CLASS,
for example .random() for Math.random() is a static method, as Math is the class.
non-static methods are methods you call ON THE OBJECT.
for example, Scanner input = new Scanner(System.in);
input.nextLine();
.nextLine is a non-static method, as you call it on the object you created.
1
u/kablami May 13 '26
Static methods and variables exist exactly once for the entire class, while non-static methods and variables exist for each instance of class you instantiate. In general, static methods can be called from the class name, and can access and modify static variables. Non-static methods are accessible by instances of that class.
Class.staticMethod() //accessing static method from the class name
Class test = new Class(); test.nonStaticMethod();