Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- After effects
- illustrator
- for문
- super
- 조건문
- 형변환
- do while문
- 메서드
- 파라미터
- expand
- static
- Overload
- length
- 상속
- Photoshop
- 멤버변수
- Override
- while문
- 생성자
- Singleton
- if문
- private
- switch문
- 배열
- 클래스
- 반복문
- Java
- 변수
- Interface
- symbol
Archives
- Today
- Total
Ms'Note
Object-7 본문
파라미터를 갖는 생성자의 이용
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 static void main(String[] args) {
Article article1 = new Article(1, "자바연습 첫번째 입니다.", "자바학생");
article1.print();
System.out.println("----------");
Article article2 = new Article(2, "자바는 객체지향 언어입니다.", "자바강사");
article2.print();
}
}
출력 결과
1
자바연습 첫번째 입니다.
자바학생
----------
2
자바는 객체지향 언어입니다.
자바강사
Comments