When do you use the static method?

Asked 2 years ago, Updated 2 years ago, 69 views

I have a question. When do you use the static method? I made the getters and setters methods. I want to make these methods callable only when an object is created. But do I have to use a static method to do this?

java static-methods

2022-09-21 20:20

1 Answers

Obj x = new Obj();
x.someMethod

Obj.someMethod

Which is the static call method?

To make the object callable only when it is created, you can just create it in the normal method.

Static methods are literally methods that already exist in memory when a class is defined. Therefore, the method exists and is callable even if the object of the class is not created. Instead, it does not access the object's variables. Because the variable of an object exists only when the object is created.


2022-09-21 20:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.