Static Flashcards

1
Q

Why do we use the static variable?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of a static method?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens when static modifier is not mentioned in the signature of the main method?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly