Skip to main content

What are access modifiers in Java?

Entry Java
Quick Answer Access modifiers control visibility: private (only within the same class), default/package-private (no keyword - within the same package), protected (same package + subclasses), public (accessible everywhere). Rule of thumb: make fields private, methods public or package-private as needed. Use the most restrictive modifier that works for your use case.

Answer

public: Accessible everywhere.
private: Inside class only.
protected: Same package + subclasses.
default: Same package.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice