Quizzesstatic Keyword — Concept Check
intermediate
java

static Keyword — Concept Check

Questions on static Keyword. Master static fields, methods, initialiser blocks, and nested classes — and understand what belongs to the class versus to each instance.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on static Keyword — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.In a Java class, you have a static field and an instance field. What happens when you change the static field from one instance?

    • AOnly the instance that changed it sees the change.
    • BThe static field changes for all instances.
    • CThe instance field changes instead.
    • DThe static field becomes immutable.
  2. 2.A developer calls a static method using an instance of the class. What is a potential issue with this approach?

    • AIt can lead to a NullPointerException.
    • BIt is misleading and can confuse readers.
    • CThe method won't execute correctly.
    • DIt will throw a compile-time error.
  3. 3.You have a static initializer block in a Java class. When does it execute?

    • AEvery time an object is created.
    • BEach time a static field is accessed.
    • CEvery time a static method is called.
    • DOnce when the class is loaded.
  4. 4.A static nested class in Java is used within a class. What is a key characteristic?

    • AIt has a reference to the enclosing class instance.
    • BIt cannot have static members itself.
    • CIt must be instantiated with an instance of the enclosing class.
    • DIt can only access static members of the enclosing class.
  5. 5.A developer mistakenly believes that static methods can access instance fields. Why is this incorrect?

    • AStatic methods are not part of the class.
    • BStatic methods are executed at compile-time.
    • CStatic methods don't have 'this' to refer to instance fields.
    • DInstance fields are private by default.
  6. 6.In the code `public static final int MAX_INSTANCES = 100;`, what is the role of `final`?

    • AIt makes MAX_INSTANCES a constant value.
    • BIt allows MAX_INSTANCES to be changed later.
    • CIt restricts MAX_INSTANCES to the class only.
    • DIt ensures MAX_INSTANCES is thread-safe.
  7. 7.A class has multiple static initializer blocks. How are they executed?

    • AIn reverse order of their declaration.
    • BRandomly during runtime.
    • CIn the order they are declared.
    • DOnly the first block is executed.
  8. 8.What is an advantage of using static methods for utility classes?

    • AThey can modify instance fields easily.
    • BThey provide functionality without needing an instance.
    • CThey require an instance to be called.
    • DThey automatically synchronize across threads.