Bird
0
0

Consider this code:

hard📝 Application Q9 of 15
Java - Static Keyword
Consider this code:
public class Counter {
    private static int count = 0;
    public static void increment() {
        count++;
    }
    public static int getCount() {
        return count;
    }
    public void reset() {
        count = 0;
    }
}

Which statement is true about calling reset()?
AIt must be called on an object instance
BIt cannot access static variables
CIt is a static method and can be called via class name
DIt can be called without creating an object
Step-by-Step Solution
Solution:
  1. Step 1: Identify method types

    reset() is non-static (instance method), others are static.
  2. Step 2: Understand calling rules

    Non-static methods must be called on an object instance.
  3. Final Answer:

    It must be called on an object instance -> Option A
  4. Quick Check:

    Instance methods require object to call [OK]
Quick Trick: Instance methods need objects; static methods don't [OK]
Common Mistakes:
  • Calling instance methods via class name
  • Assuming reset() is static
  • Thinking instance methods can't access static variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes