package javaFirstClass;
public class BankAccount {
public static void main(String[] args) {
DupRef ref1 = new DupRef();
DupRef ref2 = ref1;
ref1.deposit(3000);
ref2.deposit(2000);
ref1.withdraw(400);
ref2.withdraw(300);
ref1.checkMyBalance();
ref2.checkMyBalance();
}
}
class DupRef{
int balance =0;
public int deposit(int amount) { //입금
balance+=amount;
return balance;
}
public int withdraw(int amount) { //출금
balance-=amount;
return balance;
}
public int checkMyBalance() { //예금 조회
System.out.println("잔액: " + balance);
return balance;
}
}
잔액: 4300
잔액: 4300
728x90
'Dev. > java' 카테고리의 다른 글
Java switch 성적 처리 (0) | 2022.04.30 |
---|---|
Java if문 윤년 평년 계산하기 (0) | 2022.04.30 |
Java class (0) | 2022.04.27 |
Java 조건문(if~else) (0) | 2022.04.23 |
Java String (0) | 2022.04.23 |
댓글