Security and modularity in Java are managed through access modifiers. This project simulates a library management system where different operations require different clearance levels. By implementing four methods with distinct modifiers, we visualize the accessibility hierarchy. The project demonstrates that while most operations are available to classes within the same package, strictly private tasks remain locked within the managing class itself.
- Public Access: Universal visibility for general announcements.
- Protected Access: Access for related classes and subclasses.
- Package-Private Access: Internal module operations without explicit modifiers.
- Private Access: Strict encapsulation for sensitive financial audits.
- Java 8+ (Access Modifiers: public, protected, default, private)
- DigitalLibraryManager: The core service defining the access policy.
- DigitalLibraryApp: Entry point. The test bench located in the same package to verify visibility limits.
If the private method call is commented out:
The library is open to visitors!
A library staff meeting was held.
Book inventory completed.
Project Structure:
JavaBasics_Task_251/
├── src/
│ └── com/yurii/pavlenko/
│ ├── DigitalLibraryManager.java
│ └── DigitalLibraryApp.java
└── README.md
Code
package com.yurii.pavlenko;
public class DigitalLibraryApp {
public static void main(String[] args) {
DigitalLibraryManager manager = new DigitalLibraryManager();
manager.announceOpening();
manager.conductStaffMeeting();
manager.manageBookInventory();
/*
* INACCESSIBLE: private
* This line would cause a compilation error:
* 'handleFinancialAudits() has private access in DigitalLibraryManager'
*/
// manager.handleFinancialAudits();
}
}package com.yurii.pavlenko;
public class DigitalLibraryManager {
public void announceOpening() {
System.out.println("The library is open to visitors!");
}
protected void conductStaffMeeting() {
System.out.println("A library staff meeting was held.");
}
void manageBookInventory() {
System.out.println("Book inventory completed.");
}
private void handleFinancialAudits() {
System.out.println("Financial audit completed successfully.");
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT