배움과 복습
2017-08-31 목요일 : 수요일 과제 리뷰
뚜비콩
2017. 8. 31. 09:10
package homework; public class ConstructorExample1 { //접근 제한자 생략 가능 int num1; int num2; public ConstructorExample1(int num1, int num2){ this.num1 = num1; this.num2 = num2; this.prn(); //this. 생략 가능 /* int sum = 0; sum = num1 + num2; System.out.printf("%d + %d = %d\n", num1, num2, sum); */ } public void prn() { int sum = this.num1 + this.num2; //this. 생략 가능 System.out.println(sum); } ConstructorExample1(int[] x){ //public 생략가능->homework패키지 내에서만 쓸 수 있음 //배열로 2개 이상 받겠다고 선언할 수도 있는 거야 //이렇게 두번 선언했기 때문에 중복 선언이라고 한다 overloading } }