public&static | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

public&static

Why some functions have “public” and some have “static “ while others have neither of them

15th Apr 2020, 10:02 AM
Zhengrong Yan
Zhengrong Yan - avatar
1 Answer
+ 1
"public" is an access modifier and it means that the method is public and can be accessed even outside the class in the same package or may be in a different package. "static" means that the method belongs to the class and not to any specific instance of the class. It can be invoked even without an object but the non-static members cannot. Others might have neither of them because they need not be used everytime and a method without any access modifier specified has default access.
15th Apr 2020, 10:53 AM
Avinesh
Avinesh - avatar