임동까스
[Java] 배열 증식, class 생성자, this 본문
-
배열 증식
- if(articleSize() >= articles.length) {
Article[] newarticles = new Article[articles.length * 2];
for(int i = 0; i < articles.length ; i++) {
newarticles[i] = articles[i];
}
articles = newarticles;
}
- if(articleSize() >= articles.length) {
-
초기 값이 큰것은 좋지 않음
-
생성자
-
클래스명과 동일하게 만듦
-
return 없음
-
클래스 생성과 동시에 실행
-
public Car(String name, int number) {
this.name = name;
this.number = number;
}public Car(String name){
this.name = name;
number = 0;
}public Car(){
this("이름없음", 0);
} -
각기 다른 매개변수로 생성가능
-
-
this
- 자기 자신을 조종할 리모콘
- 나랑 같은 객체에 속해있는 변수를 가르켜라
- 변수명이 겹칠경우 붙임
- this.
'프로그래밍기초 > Java' 카테고리의 다른 글
[Java] 지역변수와 인스턴스변수 (0) | 2020.10.26 |
---|---|
[Java] 배열 끊어서 사용하기, 특정 위치 글자 가져오기 (0) | 2020.10.26 |
[Java] class 변수 형태?, 디버깅, 날짜 라이브러리 (0) | 2020.10.23 |
[Java] 객체 배열, List, ArrayList, map, hashmap 선언 (0) | 2020.10.23 |
[Java] switch, for each, method, String 추가, static (0) | 2020.10.23 |