1.생성자

1. 생성자 선언 및 사용

public	Pen(String	init_color,	int	init_price)	{
	color	=	init_color;
	price	=	init_price;
	System.out.println("생성자를	이용하여	color,	price를	초기화");
}

public	class	PenConstructorExample	{
	public	static	void	main(String[]	args)	{
		Pen	blackPen	=	new	Pen();	//	에러
		blackPen.write(1); //	에러
		Pen	redPen	=	new	Pen("빨간",	900);
		redPen.write(2);
	}
}

1.1 기본 생성자

public pen() {}

1.2 생성자 중복

 public	class	Book	{
	 String	title;
		String	author;
		int	pageCount;
		
		//	기본	생성자
		public	Book()	{	
		//	모두	기본값	설정
			this.title	=	"Unknown	Title";
			this.author	=	"Unknown	Author";
			this.pageCount	=	0;
		}
		//	일부	정보만	받는	생성자
		public	Book(String	title,	String	author)	{
			this.title	=	title;
			this.author	=	author;
			this.pageCount	=	0;	//	나머지는	기본값으로	초기화
		}
		
		//	모든	정보를	받는	생성자
		public	Book(String	title,	String	author,	int	pageCount)	{
			this.title	=	title;
			this.author	=	author;
			this.pageCount	=	pageCount;
		}
	}