Bird
0
0

Which of the following is the correct way to declare a public method in Java?

easy📝 Syntax Q12 of 15
Java - Packages and Access Control
Which of the following is the correct way to declare a public method in Java?
Avoid public myMethod() {}
Bpublic void myMethod() {}
Cprivate public void myMethod() {}
Dmethod public void myMethod() {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Java method declaration syntax

    The access modifier comes first, then the return type, then the method name and parentheses.
  2. Step 2: Check each option

    public void myMethod() {} follows correct syntax: public void myMethod() {}. Others have wrong order or invalid keywords.
  3. Final Answer:

    public void myMethod() {} -> Option B
  4. Quick Check:

    Access modifier first, then return type [OK]
Quick Trick: Access modifier always comes before return type [OK]
Common Mistakes:
  • Placing 'public' after 'void'
  • Using invalid keywords like 'method'
  • Combining multiple access modifiers incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes