Important Java Mcq 1

Which of these cannot be declared static?

a) class

b) object

c) variable

d) method


b) object


A class can be declared static only if it is a nested class. It does not require any reference from the outer class. The property of the static class is that it does not allows us to access the non-static members of the outer class. When a variable is declared static, a single copy of the variable is created and shared among all objects at the class level. Static variables are, essentially, global variables. All instances of the class share the same static variable. When a method is declared with the static keyword, it is known as the static method. The most common example of a static method is the main( ) method. So option B is optimal.

Related MCQs
Aniket Malik

Aniket Malik


Facing difficulty with

this concept?