Is it necessary that a method has to create an instance of a class in order to be used ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is it necessary that a method has to create an instance of a class in order to be used ?

8th May 2017, 5:55 PM
Ravalanatha Mallya B
Ravalanatha Mallya B - avatar
4 Answers
+ 12
Hi, maybe I misunderstand your question, but static methods don't need to have a concrete instance in order to be used. Prominent example is the Math methods. You don't need to create an instance of the Math object, instead you simly use them by refering directly to the class: Math.abs(), you name it...
8th May 2017, 6:09 PM
Senfman
Senfman - avatar
+ 11
no , you have static methods. 🐈
8th May 2017, 6:26 PM
NimWing Yuan
NimWing Yuan - avatar
+ 4
The Class is like a blueprint through the constructor an object of that class is created (instance of the class) the object may have methods that define its behavior. Once the object is created you can call those methods in your program.
8th May 2017, 6:13 PM
seamiki
seamiki - avatar
+ 3
you can just use static method and you call it by class.method instead of object.method
8th May 2017, 7:23 PM
meda