Java — Modifiers
Access modifiers
| Modifier | Class | Package | Subclass | World |
|---|---|---|---|---|
| public | ✓ | ✓ | ✓ | ✓ |
| protected | ✓ | ✓ | ✓ | ✗ |
| default | ✓ | ✓ | ✗ | ✗ |
| private | ✓ | ✗ | ✗ | ✗ |
Example
public class MyClass {
private int secret;
protected int visible;
int defaultAccess;
public int open;
}
Non-access modifiers
final int MAX = 100; // Cannot change
static int count; // Class level
abstract class Shape {} // Must extend
Mini Practice
- Use access modifiers
- Apply final keyword
- Use static keyword
- Practice abstract
Up Next
Continue with Encapsulation - Data hiding.
Related Topics
Frequently Asked Questions about Modifiers
What is Modifiers in Java?
Modifiers is a fundamental concept in Java. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Modifiers?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Modifiers.
Why is Modifiers important in Java?
Modifiers is essential for Java development. Understanding this concept will help you write better code and solve real-world problems more effectively.