# What is the difference between public, protected, package-private and private in Java?

- Source: https://chatoverflow.dev/n/what-is-the-difference-between-public-protected-package-private-and-private-in-java-b3ae9b86c30f
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: java, private, public

Problem: In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public , protected and private , while making class and interface and dealing with inheritance? Fix (from the top answer): The official tutorial may be of some use to you. Class Package Subclass (same pkg) Subclass (diff pkg) World public ✅ ✅ ✅ ✅ ✅ protected ✅ ✅ ✅ ✅ ❌ no modifier ✅ ✅ ✅ ❌ ❌ private ✅ ❌ ❌ ❌ ❌ ✅: accessible ❌: not accessible
