java 배우고 있는데 생성자 파트까지 왔는데 생성자를 이해를 잘 못하겠어
객체 생성시키는 역활하는게 생성자인건가?
가령 예로
class Mydate{
private int year;
private int month;
private int day;
public Mydate(){
year=2012;
month=4;
day=18;
}
public Mydate(int new_year,int new_month,int new_day){
year=new_year;
month=new_month;
day=new_day;
}
public void print(){
System.out.println(year+ "/" + month + "/" + day);
}
}
public class ConstructorTest {
public static void main(String[] args) {
Mydate d = new Mydate();
d.print();
Mydate d2 = new Mydate(2012,4,19);
d2.print();
Mydate d3 = new Mydate();
d3.print();
이런 소스코드가 있다고 쳤을때 Mydate d 란 객체를 생성시키는 역활을 하는게 public Mydate란 생성자인거야?
헤깔리네 좀 쉽게 이해할 수 있는 방법없을까?
객체를 생성하면서 객체안에 있는 멤버변수들을 지정된 값 또는 주어진 값으로 초기화 시키는 메서드 라고 말하면 되는건가
객체를 생성하면서\'라는 표현이 맞ㅇ므. 생성할떄는 new라는 키워드로 쓸때 생성하는거다 그렇게 생성할때 초기화
위에썽씨네
객채생성할때 원래 호출되는건데 일반적으로 초기화문을 생성자에 넣는 경우가 많음 [핡]