java - class만들기(Account-test)

imjingu·2023년 8월 14일
0

개발공부

목록 보기
367/481

Account 클래스의 경우
1) 빈 생성자가 없어서, 객체를 생성하기 위해서는 3가지의 값이 필요
2) setter가 없기 때문에 객체 생성시에 이름과 계좌번호를 입력하면
이후로는 값을 변경할 수 없음
예금 잔고는 withdraw(), deposit()으로 변경 가능

package chapter20230814;

public class Test {

	public static void main(String[] args) {
		
		
		Account chulsoo = new Account("철수", "123456", 1000); // 철수의 계좌
		Account younghee = new Account("영희", "654321", 200); // 영희의 계좌
		
		// chulsoo.balance = 200; // balance가 private 속성이라 외부 클래스에서 접근이 안됨
		chulsoo.withdraw(200); // 철수가 200원을 인출
		younghee.deposit(100); // 영희가 100원을 예금
		
		System.out.println(" 철수의 계좌");
		System.out.println(" 계좌명의 : " + chulsoo.getName());
		System.out.println(" 계좌번호 : " + chulsoo.getNo());
		System.out.println(" 예금잔고 : " + chulsoo.getBalance());
		
		System.out.println(" 영희의 계좌");
		System.out.println(" 계좌명의 : " + younghee.getName());
		System.out.println(" 계좌번호 : " + younghee.getNo());
		System.out.println(" 예금잔고 : " + younghee.getBalance());
		
		System.out.println(chulsoo); // 원래는 주소가 나왔지만 @Override 를 통해 값을 출력

	}

}

0개의 댓글