728x90
반응형
[Error Note] 6. The constructor - is undefiend
참조변수 s2를 선언하고,
Student 클래스 내부의 showInfo 메서드를 호출하던 중 에러가 발생했다.
잘 살펴보면 s2를 선언하는 부분에서 에러가 발생한 것을 확인할 수 있다.
아래 사용자 정의 생성자를 보자. (Student 클래스)
Student 클래스를 인스턴스화 할 때,
문자열 변수 s, 정수형 변수 n1, n2까지 총 3개의 변수를 초기화하게끔 되어있다.
각각의 변수는 Student 내의 name, number, grade에 초기화된다.
즉, 위의 코드에서는 초기화해야 할 변수를 입력하지 않았기 때문에 에러가 발생했다는 사실을 알 수 있다.
다시 처음 코드로 돌아가보자.
이번에는 s2을 선언할 때, 사용자 정의 생성자에 따라 "임꺽정", 222, 11이라는 변수를 초기화했다.
이제 에러가 잘 해결된 것을 확인할 수 있다.
사용자 정의 생성자를 사용할 때 유의해야 할 부분인 것 같다.
728x90
반응형