Static Flashcards
Why do we use the static variable?
Static variables are common properties for all objects of a class. I.e it is a class level variable. This variable is only loaded once at the time of class loading, so it saves memory.
What is the purpose of a static method?
A static method is common to all the objects of a class. We do not have to create an object of a class to call a static method. So it provides the convenience of not having to create an object to call it.
What happens when static modifier is not mentioned in the signature of the main method?
As per Java specification, main method has to be marked as static. A program can compile with a non-static main method, but on execution it will give a NoSuchMethod exception.