Bird
0
0

Which of the following statements about the public access modifier is TRUE?

easy📝 Conceptual Q2 of 15
Java - Packages and Access Control
Which of the following statements about the public access modifier is TRUE?
AA public class can be accessed only within its own package.
BA public method can be accessed from any other class.
CA public variable cannot be accessed outside its class.
DA public constructor is private by default.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze each statement

    A is true: public methods can be accessed from any class. B is false: public classes are accessible everywhere. C is false: public variables are accessible outside the class. D is false: constructors are not private by default.
  2. Step 2: Confirm the true statement

    Only statement A is true.
  3. Final Answer:

    A public method can be accessed from any other class. -> Option B
  4. Quick Check:

    Public method access = global [OK]
Quick Trick: Public methods are accessible everywhere [OK]
Common Mistakes:
  • Assuming public limits access to package
  • Confusing constructor default access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes