---
title: "In Java, what's the difference between public, default, protected, and private?"  
description: "In Java, what's the difference between public, default, protected, and private?"  
author: "Royce Roy"  
published: 2015-05-06  
updated: 2015-05-06  
canonical: https://www.mindstick.com/forum/23193/in-java-what-s-the-difference-between-public-default-protected-and-private  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# In Java, what's the difference between public, default, protected, and private?

Are there clear [rules](https://www.mindstick.com/articles/43901/blackjack-rules) on when to use each of these when making classes and [interfaces](https://www.mindstick.com/articles/12100/interfaces-in-java-real-life-example) and dealing with [inheritance](https://www.mindstick.com/articles/13095/inheritance-and-its-types)?

## Replies

### Reply by Anonymous User

This Java tutorial may be of some use to you.\

```
Modifier    | Class | Package | Subclass | World
————————————+———————+—————————+——————————+———————
public      |  y    |    y    |    y     |   y
————————————+———————+—————————+——————————+———————
protected   |  y    |    y    |    y     |   n
————————————+———————+—————————+——————————+———————
no modifier |  y    |    y    |    n     |   n    **also known as package-private**
————————————+———————+—————————+——————————+———————
private     |  y    |    n    |    n     |   n

y: accessible
n: not accessible
```


---

Original Source: https://www.mindstick.com/forum/23193/in-java-what-s-the-difference-between-public-default-protected-and-private

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
