Skip to content

danielcregg/encap-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Encapsulation Example

Java License: MIT Last Commit

A simple Java demonstration of encapsulation using a SavingsAccount class with private fields and public getter/setter methods.

Overview

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.

Features

  • Private instance variables enforcing data hiding
  • Public getter and setter methods for controlled access
  • Default and parameterised constructors
  • Simple Main class demonstrating object creation and method usage

Prerequisites

Getting Started

Installation

git clone https://github.com/danielcregg/encap-example.git
cd encap-example

Usage

Compile and run the program:

javac Main.java SavingsAccount.java
java Main

Expected output:

1000
Sean Murphy
123456
1250

Tech Stack

Category Technology
Language Java
Paradigm Object-Oriented Programming

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Java encapsulation demo with a SavingsAccount class using private fields and getter/setter methods

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages