프로그래밍기초/Java
[Java] 배열 증식, class 생성자, this
임동까스
2020. 10. 23. 10:03
-
배열 증식
- 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.