Bird
0
0

Which of the following is the correct way to declare a static variable in Java?

easy📝 Syntax Q12 of 15
Java - Static Keyword
Which of the following is the correct way to declare a static variable in Java?
Aint count static = 0;
Bint static count = 0;
Ccount static int = 0;
Dstatic int count = 0;
Step-by-Step Solution
Solution:
  1. Step 1: Recall Java syntax for static variables

    The keyword static comes before the data type in variable declaration.
  2. Step 2: Match the correct syntax

    static int count = 0; uses static int count = 0; which is the correct order.
  3. Final Answer:

    static int count = 0; -> Option D
  4. Quick Check:

    static before type = correct syntax [OK]
Quick Trick: Put static before the type when declaring variables [OK]
Common Mistakes:
  • Placing static after the variable name
  • Using invalid order of keywords
  • Confusing static with final keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes