Skip to content

Instantly share code, notes, and snippets.

@Pooshan
Created September 18, 2016 17:04
Show Gist options
  • Save Pooshan/abf7511db914458847f1d1a4addcde7f to your computer and use it in GitHub Desktop.
Save Pooshan/abf7511db914458847f1d1a4addcde7f to your computer and use it in GitHub Desktop.
// bank.java
// demonstrate basic OOP syntax
Class BankAccount
{
//account balance
private double balance;
//Constructor — Initializing constructor is very important
public BankAccount(double openingBalance);
{
balance = openingBalance;
}
//make deposits
public void deposit(double amount)
{
balance = balance + amount
}
//make withdrawal
public void withdraw(double amount)
{
balance = balance – amount;
}
//Display result
public void Display()
{
System.out.println(“balance = “ + balance);
}
}// end of Class.
Class BankApp
{
public stick void main(String[] args)
{
// Create account
BankAccount ba1 = new BankAccount(100.00);
System.out.print(“Before Transaction, “);
//Display Balance
ba1.display();
//Make Deposit
ba1.deposit(70.11);
// Make Withdraw
ba1.withdraw(10.11);
System.out.println(“After Transaction, “);
ba1.display();
} //end main()
}// end class BankApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment