Bird
0
0

You want to design two classes in the same package where one class can access the other's methods without using public or protected modifiers. Which access modifier should you use?

hard📝 Application Q8 of 15
Java - Packages and Access Control
You want to design two classes in the same package where one class can access the other's methods without using public or protected modifiers. Which access modifier should you use?
APrivate access modifier
BDefault access modifier (no keyword)
CPublic access modifier
DProtected access modifier
Step-by-Step Solution
Solution:
  1. Step 1: Understand access needs

    Classes in the same package need to access each other's methods without exposing them outside.
  2. Step 2: Choose access modifier

    Default access modifier allows access within the same package without using public or protected.
  3. Final Answer:

    Default access modifier (no keyword) -> Option B
  4. Quick Check:

    Default access = package-only access, perfect for this case [OK]
Quick Trick: No keyword means package-only access, ideal for same package use [OK]
Common Mistakes:
  • Choosing private which restricts access to same class only
  • Choosing public which exposes to all packages
  • Choosing protected which allows subclass access outside package

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes