스크린샷 2025-08-08 오후 3.58.04.png

package com.haenin.section04.section05.overloading;

public class OverloadingTest {

    /* 목표, 오버로딩(Overloading) 에 대해 이해할 수 있다. */
    /* 설명.
    *   메소드의 시그니처
    *    public void method(int num){} 이라며느 메소드의 메소드명과 파라미터 선언부 부분을
    *    메소드의 시그니처(signature)라고 한다.(즉, method(int num))
    *
    *   설명.
    *    동일한 메소드 이름으로 다양한 종류의 매개변수에 따라 처리해야 하는 경우 적용할 수 기술을
    *    오버로딩이라고 한다.
    *
    *   설명.
    *    오버로딩의 조건?
    *     매개 변수의 타입, 갯수, 순서를 다르게 작성하여 하나의 클래스 내에 동일한 이름의 메소드를
    *     여러개 작성할 수 있다.
    * */
    public void test() {}

    public void test(int num) {}

    public void test(int num1, int num2) {}

//    public String test() {} // 필기. 반환형이 달라도 이름이 동일해서 오류
//    public void test(int num2, int num1) {}

    public void test(int num, String str) {}
    public void test(String str, int num) {}

}

package com.haenin.section04.section05.parameter;

import java.util.Arrays;

public class Application {

    public static void main(String... args) {
        /* 목표, 메소드와 파라미터(매개변수)에 대해 이해하고 사용할 수 있다. */
        ParameterTest pt = new ParameterTest();
        
        /* 목차. 1. 기본자료형을 매개변수로 전달 받는 메소드 호출 */
        int num = 20;
        System.out.println("call by value 전: "+ num);
        pt.testPrimitiveTypeParameter(num);
        System.out.println("call by value 후: "+ num);

        /* 목차. 2. 기본자료형 배열을 매개변수로 전달 받는 메소드 호출 */
        int[] iArr = new int[]{1, 2, 3, 4, 5};
        System.out.println("호출 전: "+ Arrays.toString(iArr));
        pt.testPrimitiveArrayTypeParameter(iArr);
        System.out.println("호출 전: "+ Arrays.toString(iArr));

        /* 목차. 3. 클래스 자료형을 매개변수로 전달 받는 메소드 호출 */
        Rectangle rect = new Rectangle(4,5);
        rect.calArea();
        rect.calRound();
        pt.testClassTypeParameter(rect);

        /* 목차. 4. 객체 배열은 배우지 않았으므로 뒤에서 다시 나올 예정 */
        /* 목차. 5. 가변인자를 매개변수로 전달 받는 메소드 호출(자바는 웬만하면 권장x) */
        pt.testVariableLengthArrayParameter();
        pt.testVariableLengthArrayParameter("홍길동");
        pt.testVariableLengthArrayParameter("유관순", "볼링");
        pt.testVariableLengthArrayParameter(new String[]{"강감찬", "낚시", "독서"});

    }
}

package com.haenin.section04.section05.parameter;

import java.util.Arrays;

public class ParameterTest {
    public void testPrimitiveTypeParameter(int num) {
        num += 1;
        System.out.println("메소드 안 num = " + num);
    }

    public void testPrimitiveArrayTypeParameter(int[] iArr) {
        iArr[0]=10;
        System.out.println("메소드 안 iArr = " + Arrays.toString(iArr));
    }
    public void testClassTypeParameter(Rectangle r){
        r.calArea();
        r.calRound();
    }
    // 필기. 하나의 타입으로 String 배열로 만들어 줌
    public void testVariableLengthArrayParameter(String... str) {
        System.out.println("넘어온 인자 출력: "+ Arrays.toString(str));

    }

}

package com.haenin.section04.section05.parameter;

public class Rectangle {
    private int height;
    private int width;

    public Rectangle() {
    }

    public Rectangle(int width, int height) {
        this.width = width;
        this.height = height;
    }
    public void calArea() {

    }

    public void calRound() {

    }
}