Bird
0
0

Which of the following is the correct way to declare a class with default access modifier?

easy📝 Syntax Q12 of 15
Java - Packages and Access Control
Which of the following is the correct way to declare a class with default access modifier?
Aclass MyClass {}
Bprivate class MyClass {}
Cdefault class MyClass {}
Dpublic class MyClass {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall syntax for default access modifier

    Default access means no access keyword is written before the class name.
  2. Step 2: Check each option

    class MyClass {} declares the class without any access keyword, which means default access. Options A and B use explicit keywords, and C uses a non-existent keyword.
  3. Final Answer:

    class MyClass {} -> Option A
  4. Quick Check:

    No keyword = default access [OK]
Quick Trick: No keyword before class means default access [OK]
Common Mistakes:
  • Using 'default' keyword which does not exist in Java
  • Confusing private with default
  • Always using public by habit

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes