Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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
Tags
more
Archives
Today
Total
관리 메뉴

임동까스

[Java] 배열 증식, class 생성자, this 본문

프로그래밍기초/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;
      }
  • 초기 값이 큰것은 좋지 않음

  • 생성자

    • 클래스명과 동일하게 만듦

    • 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.