+ 1

Why static is used in code: static void speak(){ }

Please explain what is static and where to use.

23rd Jul 2019, 10:27 AM
Satnam Singh
3 ответов
+ 3
Static methods belong to the class which means you dont need to create an instance of that class to access its static methods. This means when you create objects of this class each object you create has accsess to the same static method no matter what object your calling it from. Hope that makes sense
23rd Jul 2019, 11:56 AM
D_Stark
D_Stark - avatar
+ 4
Hope this code helps you: https://code.sololearn.com/cxu6k4yBVy2g/?ref=app static -> belongs to class non static -> belongs to an instance of class
24th Jul 2019, 11:17 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Can you explain with example plz.
23rd Jul 2019, 6:28 PM
Satnam Singh