Overloading2 자바(JAVA) - 예약어 this this 사용 용도 자신의 메모리를 가리킴 생성자에서 다른 생성자를 호출 자신의 주소를 반환 public class Student { int studentID; String studentName; int grade; // 자신의 메모리를 가리킴 public Student(int studentID, String studentName) { this.studentID = studentID; this.studentName = studentName; } // 생성자에서 다른 생성자를 호출 public Student() { this(0, "이름없음") } // 자신의 주소를 반환 public Student showthis() { return this; } } 자신의 메모리를 가리킴 public class Stude.. 2022. 3. 16. 자바(JAVA) - 생성자(constructor) 생성자(contructor) 인스턴스를 초기화할 때의 명령어 집합 생성자의 이름 = 그 클래스의 이름 생성자는 메소드X, 상속X, 리턴값X public class Student { int studentID; String studentName; int grade; String address; public String getStudentName() { return studentName; } } 위와같은 클래스를 생성했을때 아래 코드와 같이 인스턴스를 생성할 수 있다. Student studentA = new Student(); 클래스 내에 따로 생성자를 만들지 않았지만 Student()라는 생성자를 통해 인스턴스를 생성하였다 클래스 내에 따로 생성자를 만들지 않으면 JAVA Compiler가 디폴트 생성자를.. 2022. 3. 9. 이전 1 다음