What is static in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is static in java

4th Feb 2017, 6:03 PM
missta
2 Answers
+ 2
if you make a variable/method inside a class static it means we can use/invoke that variable/method without creating an object. That's why we always write -public static void main(..) so we dont need to create an object for class containing main method.
4th Feb 2017, 6:14 PM
Pankaj Singha
+ 1
class abc{ static meth(){…} } class prog{ public static void main(String args[]){ abc.meth(); } } /*alternatively, abc obj=new abc(); obj.meth(); here,creating an object may waste memory in heap area if meth() is some small method*/
4th Feb 2017, 6:22 PM
Pankaj Singha