일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- After effects
- for문
- super
- private
- Overload
- switch문
- expand
- Java
- length
- 반복문
- do while문
- Interface
- 변수
- symbol
- 메서드
- if문
- Singleton
- 상속
- Override
- 조건문
- 파라미터
- 멤버변수
- static
- 클래스
- 배열
- 형변환
- 생성자
- Photoshop
- illustrator
- while문
- Today
- Total
목록생성자 (4)
Ms'Note

생성자 Overload 파라미터가 서로 다른 생성자들이 하나의 완전한 생성자를 호출하도록 하여, 데이터의 초기화를 한 곳에서 일괄적으로 처리하도록 구현할 수 있다. public class Article { private int seq; private String subject; private String writer; public Article(int seq, String subject, String writer) { super(); this.seq = seq; this.subject = subject; this.writer = writer; } public Article(int seq) { tihs(seq, "제목없음", "익명"); } public Article(int seq, String subje..
생성자란? new 키워드를 사용하여 객체가 생성될 때 자동으로 실행되는 특수한 형태의 메서드 리턴형을 명시하지 않으며, 메서드의 이름은 클래스와 동일하다. class Foo { Foo() { // 이 안은 객체가 생성될 때 자동으로 호출된다. } } 자동으로 실행된다는 특성 때문에, 객체가 생성되면서 해당 객체의 특성을 초기화 하기 위하여 사용된다. (EX : 멤버변수의 초기값을 할당하는 용도) 파라미터를 갖는 생성자 생성자도 메서드의 한 종류이므로 파라미터를 함께 정의하는 것이 가능하다. 생성자의 파라미터를 멤버변수에 복사하는 것으로 객체의 초기화를 외부적인 요인에 의해 처리할 수 있다. class Foo { String name; int age; Foo(String name, int age) { //..
파라미터를 갖는 생성자의 이용 class Article { int seq; String subject; String writer; // 파라미터가 존재하는 생성자 // --> 파라미터에 의해서 멤버변수의 값을 초기화 한다. public Article(int seq, String subject, String writer) { this.seq = seq; this.subject = subject; this.writer = writer; } public void print() { System.out.println(this.seq); System.out.println(this.subject); System.out.println(this.writer); } } public class Main07 { public ..
생성자의 활용 생성자는 멤버변수의 값을 초기화 하기 위해 사용한다. class Book{ String subject; String content; // 생성자 - 객체가 생성될 때, 자동으로 실행되는 특수한 메서드 // 특징 : 리턴형을 명시하지 않는다. 클래스와 이름이 동일하다. Book(){ System.out.println("-------생성자 실행됨-------"); this.subject = "JAVA입문"; this.content = "JAVA는 ~~~..."; } void read(){ System.out.println("------read() 실행됨------"); System.out.println(this.subject); System.out.println(this.content); } ..