Java

Packages & Access Modifiers

Organize your code with Packages and control visibility with Access Modifiers.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Organize your code with Packages and control visibility with Access Modifiers. This hands-on tutorial focuses on practical implementation of packages & access modifiers concepts.

Packages & Access Modifiers

Packages

A package in Java is used to group related classes. Think of it as a folder in a file directory.

  • Built-in Packages: java.util, java.io, etc.
  • User-defined Packages: Created by you.

To use a class from a package, you import it:

import java.util.Scanner;

Access Modifiers

These text keywords set the visibility (accessibility) of classes, methods, and other members.

ModifierClassPackageSubclass (diff pkg)World
publicYesYesYesYes
protectedYesYesYesNo
defaultYesYesNoNo
privateYesNoNoNo
  • private: Only purely within the class.
  • default: Only within the package.
  • protected: Within package + subclasses.
  • public: Everywhere.

Interactive Code

See access modifiers in action (conceptual simulation).

JAVA PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "Java packages and 4 access modifiers: public, private, protected, default"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 3

Which modifier makes a member accessible only within its own class?

public
protected
private
default

Next Steps

Now we move to one of the most powerful parts of Java: The Collections Framework.