A simple Java demonstration of encapsulation using a SavingsAccount class with private fields and public getter/setter methods.
This project illustrates the object-oriented programming principle of encapsulation in Java. A SavingsAccount class encapsulates account data (holder name, account number, and balance) behind private instance variables, exposing controlled access through public getter and setter methods. A Main class demonstrates creating an account object, reading its properties, and modifying them through the public interface.
- Private instance variables enforcing data hiding
- Public getter and setter methods for controlled access
- Default and parameterised constructors
- Simple
Mainclass demonstrating object creation and method usage
- Java JDK 8 or higher
git clone https://github.com/danielcregg/encap-example.git
cd encap-exampleCompile and run the program:
javac Main.java SavingsAccount.java
java MainExpected output:
1000
Sean Murphy
123456
1250
| Category | Technology |
|---|---|
| Language | Java |
| Paradigm | Object-Oriented Programming |
This project is licensed under the MIT License. See the LICENSE file for details.