static 메소드


<aside> 🪡

설명


코드


package static1;

public class DecoUtil1 {

    public static String deco(String str) {
        String result = "*" + str + "*";
        return result;
    }
}

--------------------------------------------
package static1;

public class DecoMain1 {

    public static void main(String[] args) {
        String a = "hello java";
        String b = DecoUtil1.deco(a);

        System.out.println(a);
        System.out.println(b);
    }
}

위와 같이
DecoUtil1 util = new DecoUtil1(); 객체 생성 없이
String b = DecoUtil1.deco(a)처럼 바로 호출하여 사용 가능

</aside>