+ 2
What is static in java
2 Réponses
+ 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.
+ 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*/