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:
Step 1: Recall syntax for default access modifier
Default access means no access keyword is written before the class name.
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.
Final Answer:
class MyClass {} -> Option A
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
Master "Packages and Access Control" in Java
9 interactive learning modes - each teaches the same concept differently