
//////// 메인 클래스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | package project1105; class testmain { public static void main(String[] args) { System.out.println("이름, 폰번호, 생년월일 입력"); PhoneInfo ph = new PhoneInfo("김근우","010-1234-5678","1999년생"); ph.shows(); System.out.println(); PhoneInfo ph2 = new PhoneInfo("김근우","010-1234-5678"); ph2.shows(); } } | cs |
////////////phoneInfo 클래스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /* * 단 생년월일 정보는 저장을 할수도 저장하지 않을수도 잇게끔 생성자를 정의하자. * 정의된 클래스의 확인을 위한 메인메소드 간단히정의하자 */ package project1105; public class PhoneInfo { String name; String phoneNumber; String birthday; public PhoneInfo(String name, String phoneNumber, String birthday ) { if (birthday=="0"){ //System.out.println("생년월일을 모릅니다."); this.birthday = "모름"; this.name = name; this.phoneNumber = phoneNumber; } else{ this.name = name; this.phoneNumber = phoneNumber; this.birthday = birthday; } } public PhoneInfo(String name, String phoneNumber) { //System.out.println("test NO NUM"); this(name,phoneNumber,"0"); } public void shows() { System.out.println("이름: "+ name+"\n"+"폰 번호: "+phoneNumber+ "\n생년월일: "+birthday); } } | cs |