In secure system design, certain global parameters must be hidden from the outside world but accessible to internal monitoring modules. This project demonstrates how a Static Nested Class (SecurityDisplayUnit) can access a private static field (securityLevel) of its outer class (Vault). This pattern allows for clean logical grouping of utility or display components that depend on the global state of the parent class without requiring an instance of that parent.
- Private Static Field: Encapsulated the
securityLevelwithin theVaultclass. - Static Nested Class: Implemented
SecurityDisplayUnitas a static member to allow independent instantiation. - Internal Access: Proven that nested classes bypass standard private access restrictions of their outer class.
- Independent Lifecycle: Successfully displayed the security level without creating a
Vaultobject.
- Java 8+ (Static Nested Classes, Static Field Access, Encapsulation)
- Vault: The outer class containing the master security configuration.
- SecurityDisplayUnit: The static nested class responsible for data visualization.
- SecurityApp: The entry point for system verification.
Security level: 100
Project Structure:
JavaBasics_Task_269/
├── src/
│ └── com/yurii/pavlenko/
│ ├── Vault.java
│ └── SecurityApp.java
└── README.md
Code
package com.yurii.pavlenko;
public class SecurityApp {
public static void main(String[] args) {
Vault.SecurityDisplayUnit display = new Vault.SecurityDisplayUnit();
display.showSecurityLevel();
}
}package com.yurii.pavlenko;
public class Vault {
private static int securityLevel = 100;
public static class SecurityDisplayUnit {
public void showSecurityLevel() {
System.out.println("Security level: " + Vault.securityLevel);
}
}
}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