Bird
0
0

Which of the following statements about private data members in Java is CORRECT?

hard📝 Conceptual Q10 of 15
Java - Encapsulation
Which of the following statements about private data members in Java is CORRECT?
APrivate data members are accessible by any class in the same package.
BPrivate data members cannot be accessed directly outside their class, even by subclasses.
CPrivate data members can be accessed directly by subclasses.
DPrivate data members are accessible globally if declared static.
Step-by-Step Solution
Solution:
  1. Step 1: Recall private access rules

    Private members are accessible only within the class they are declared.
  2. Step 2: Analyze options

    Private data members cannot be accessed directly outside their class, even by subclasses. correctly states that subclasses cannot access private members directly.
  3. Step 3: Clarify misconceptions

    Package access and static do not override private restrictions.
  4. Final Answer:

    Private data members cannot be accessed directly outside their class, even by subclasses. -> Option B
  5. Quick Check:

    Private means class-only access, no subclass access [OK]
Quick Trick: Private means accessible only inside declaring class [OK]
Common Mistakes:
  • Assuming subclasses can access private members
  • Confusing private with protected or package-private

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes