day17_EmployeeTest

육희영·2021년 10월 28일
0
package com.java1.day17;

public class EmployeeTest {

	public static void main(String[] args) {
		Date birth = new Date(1990, 1, 1);
		Employee employee = new Employee("홍길동", birth);
		System.out.println(employee);

	}

}
class Employee {
	private String name;
	private Date birthDate;

	public Employee(String name, Date birthDate) {
		this.name = name;
		this.birthDate = birthDate;
	}

	@Override
	public String toString() {
		return "Employee[name=" + name + ",birthDate=" + birthDate + "]";
	} // birthDate 뒤에 .toString() 이 생략 되어 있다.
}

class Date{
	private int year;
	private int month;
	private int date;
	
	public Date(int year, int month, int date) {
		this.year = year;
		this.month = month;
		this.date = date;
	}
	
	@Override
	public String toString() {
		return "Date[year="+year+",month="+month+",date="+date+"]";
	}
}

출력결과

Employee[name=홍길동,birthDate=Date[year=1990,month=1,date=1]]

0개의 댓글

관련 채용 정보