+ 1
Why static is used in code: static void speak(){ }
Please explain what is static and where to use.
3 Respuestas
+ 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
+ 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
+ 1
Can you explain with example plz.