[{"data":1,"prerenderedAt":345},["ShallowReactive",2],{"post-document:\u002Fjava\u002Foop\u002F2026\u002F08\u002F11\u002Fjava-static-nested-class\u002F":3},{"id":4,"title":5,"body":6,"categories":321,"date":324,"description":325,"extension":326,"image":327,"key_concepts":327,"last_modified_at":327,"legacyPath":328,"meta":329,"navigation":331,"part":332,"path":333,"published":331,"robots":327,"seo":334,"series":335,"stem":336,"strengths":327,"summary":327,"tags":337,"tradeoffs":327,"__hash__":344},"posts\u002Fposts\u002FBackend\u002FJAVA\u002Foop\u002F2026-08-11-java-static-nested-class.md","Java 객체지향 Part 5: static 메서드와 중첩 클래스",{"type":7,"value":8,"toc":307},"minimark",[9,13,17,22,25,28,39,42,45,48,51,54,57,61,64,67,70,73,76,80,84,87,90,96,98,101,104,107,111,114,120,122,125,128,132,135,138,141,144,150,153,158,161,164,168,171,177,180,183,188,191,194,200,202,205,208,211,214,217,220,223,226,229,232,235,241,243,246,249,252,256,259,262,265,268,271,274,278,281,284,287,290,293,296,299,302,304],[10,11,5],"h2",{"id":12},"java-객체지향-part-5-static-메서드와-중첩-클래스",[14,15,16],"p",{},"중첩 클래스에서 Static을 붙이는 이유는 바깥 객체와 연결되지 않은 클래스를 내부에 묶어두기 위해서이다.",[18,19,21],"h3",{"id":20},"일반-내부-클래스","일반 내부 클래스",[14,23,24],{},"tatic이 없는 내부 클래스는 바깥 객체에 소속",[14,26,27],{},"class User {\nString name = \"민형\";",[29,30,35],"pre",{"className":31,"code":33,"language":34},[32],"language-text","class Profile {\n    void printName() {\n        System.out.println(name); \n    }\n}\n","text",[36,37,33],"code",{"__ignoreMap":38},"",[14,40,41],{},"}",[14,43,44],{},"따라서 Profile 객체를 만들려면 먼저 User 객체가 필요하다.",[14,46,47],{},"User user = new User();\nUser.profile profile = user.new Profile();",[14,49,50],{},"구조를 개념적으로 보면 다음과 같다.",[14,52,53],{},"User 객체\n└── Profile 객체\n└── 바깥 User 객체를 참조",[14,55,56],{},"profile이 특정 User의 name을 사용하므로 바깥 객체와 연결되는 것이 자연스럽다",[18,58,60],{"id":59},"static-중첩-클래스","Static 중첩 클래스",[14,62,63],{},"static 중첩 클래스는 바깥 객체와 연결되지 않는다.",[14,65,66],{},"class User {\nstatic class Profile{\nvoid printMessage(){\nSystem.out.println(\"프로필입니다.\")\n}\n}\n}",[14,68,69],{},"User.Profile profile = new User.Profile();",[14,71,72],{},"profile.printMessage();",[14,74,75],{},"여기서 User.Profile 이라고 쓰지만, 특정 User 객체에 소속된 것은 아니다.\n단지 User와 관련된 클래스라서 User 내부에 정리한 것",[10,77,79],{"id":78},"왜-static을-사용하는가","왜 Static을 사용하는가?",[18,81,83],{"id":82},"_1-바깥-객체가-필요없기-때문에","1. 바깥 객체가 필요없기 때문에",[14,85,86],{},"다음 Address는 특정 User 객체의 필드에 직접 접근할 필요가 없다.",[14,88,89],{},"class User{\nstatic class Address{\nString city;",[29,91,94],{"className":92,"code":93,"language":34},[32],"    Address(String city){\n        this.city = city; \n    }\n}\n",[36,95,93],{"__ignoreMap":38},[14,97,41],{},[14,99,100],{},"Address에 접근하고 싶다면",[14,102,103],{},"User.Address address = new User.Address(\"판교\")",[14,105,106],{},"바깥 객체가 필요 없는데 일반 내부 클래스로 만들면 불필요하게 User 객체와 연결된다.",[18,108,110],{"id":109},"_2-관련-클래스를-한-곳에-묶을-수-있기-때문에","2. 관련 클래스를 한 곳에 묶을 수 있기 때문에",[14,112,113],{},"class HttpResponse{\nstatic class Header{",[29,115,118],{"className":116,"code":117,"language":34},[32],"}\nstatic class Body{\n\n}\n",[36,119,117],{"__ignoreMap":38},[14,121,41],{},[14,123,124],{},"Header 와 Body가 HttpsResponse와 관련있다는 것을 구조적으로 표현할 수 있다.",[14,126,127],{},"HttpResponse.Header header  = new HttpResponse.Header();\nHttpResponse.Body body = new HttpResponse.Body();",[10,129,131],{"id":130},"_3-불필요한-바깥-객체-참조를-막기-때문에","3. 불필요한 바깥 객체 참조를 막기 때문에",[14,133,134],{},"일반 내부 클래스 객체는 내부적으로 바깥 객체를 참조",[14,136,137],{},"내부 클래스 객체 ──참조──→ 바깥 클래스 객체",[14,139,140],{},"하지만 static 중첩 클래스에은 그 참조가 없다.",[14,142,143],{},"static 중첩 클래스 객체     바깥 클래스 객체",[29,145,148],{"className":146,"code":147,"language":34},[32],"      서로 독립적\n",[36,149,147],{"__ignoreMap":38},[14,151,152],{},"바깥 객체가 필요하지 않다면 static 중첩 클래스를 사용해야 구조가 단순하고\n불필요한 객체 참조도 생기지 않는다.",[154,155,157],"h4",{"id":156},"개념-확인-문제","개념 확인 문제",[14,159,160],{},"Receipt 클래스는 특정 Order 객체의 orderNumber를 직접 사용해야 한다.",[14,162,163],{},"Receipt는 특정 Order 객체의 orderNumber를 사용해야 하므로 일반 내부 클래스로 선언해야 한다. 일반 내부 클래스는 자신을 생성한 바깥 Order 객체를 참조할 수 있기 때문에",[10,165,167],{"id":166},"static-메서드","Static 메서드",[14,169,170],{},"판단 기준",[172,173,174],"blockquote",{},[14,175,176],{},"클래스의 필드를 사용하느냐?\n더 자세하게는, 이 기능이 특정 객체의 행동인가, 아니면 객체와 상관없는 공통 기능인가?",[14,178,179],{},"특정 객체의 데이터가 필요하지 않을 때 사용한다.",[14,181,182],{},"판단할 떄 이렇게 생각하면 된다.",[172,184,185],{},[14,186,187],{},"이 기능을 실행하려면 특정 객체가 꼭 필요한가?",[14,189,190],{},"필요하면 일반 인스턴스 메서드",[14,192,193],{},"class User{\nstring name;",[29,195,198],{"className":196,"code":197,"language":34},[32],"void printName() {}\n    System.out.println(name); \n",[36,199,197],{"__ignoreMap":38},[14,201,41],{},[14,203,204],{},"printName()은 특정 User 객체의 name이 필요하다.",[14,206,207],{},"User user = new User();\nuser.name = \"민형\";\nuser.printName();",[209,210],"hr",{},[14,212,213],{},"반대로 특정 객체의 데이터가 필요하지 않으면 static 메서드를 사용할 수 있다.",[14,215,216],{},"class Calculator {\nstatic int add(int a, int b,){\nreturn a + b;\n}\n}",[14,218,219],{},"add()는 어떤 calculator 객체의 상태도 사용하지 않으므로...",[14,221,222],{},"int result = Calculator.add(10,20);",[14,224,225],{},"정리하면",[14,227,228],{},"특정 객체의 필드가 필요한가?\n├── 필요함 → 일반 인스턴스 메서드\n└── 필요 없음 → static 메서드 고려",[14,230,231],{},"예를 들어 Order에서 특정 주문 번호를 출력하다면 일반 메서드가 자연스러움",[14,233,234],{},"class Order{\nString orderNumber;",[29,236,239],{"className":237,"code":238,"language":34},[32],"void printOrderNumber() {\n    System.out.println(orderNumber); \n}\n",[36,240,238],{"__ignoreMap":38},[14,242,41],{},[14,244,245],{},"하지만 주문 번호의 형식만 검사한다면 특정 Order 객체가 없어도 된다.",[14,247,248],{},"class Order {\nstatic boolean isValidOrderNumber(String orderNumber) {\nreturn orderNumber.startsWith(\"ORDER-\");\n}\n}",[14,250,251],{},"boolean valid = Order.isValidOrderNumber(\"ORDER-100\");",[154,253,255],{"id":254},"근데-그냥-필드-선언-안하고-쓰면-되는-거-아닌가","근데 그냥 필드 선언 안하고 쓰면 되는 거 아닌가?",[14,257,258],{},"class Calculator {\nint add(int a, int b) {\nreturn a + b;\n}\n}",[14,260,261],{},"class Calculator {\nstatic int add(int a, int b) {\nreturn a + b;\n}\n}",[14,263,264],{},"두 메서드는 모두 전달받은 값만 계산 -> 차이는 호출 방식",[14,266,267],{},"\u002F\u002F 일반 메서드\nCalculator calculator = new Calculator();\ncalculator.add(10,20):",[14,269,270],{},"\u002F\u002F static 메서드\nCalculator.add(10, 20);",[14,272,273],{},"일반 메서드는 필드를 사용하지 않더라도 객체를 먼저 만들어야 합니다. 반면 static 메서드는 객체 없이 실행할 수 있다.\n-> 이거는 객체를 만들지 않아서 상당히 편리하다!",[154,275,277],{"id":276},"그러면-static-method는-언제-안써야-하는가","그러면 Static method는 언제 안써야 하는가?",[14,279,280],{},"나중에 구현을 객체마다 다르게 바꿔야 한다면 일반 베서드로 구현해야 한다.",[14,282,283],{},"class Calculator {\nint calculate(int a, int b) {\nreturn a + b;\n}\n}",[14,285,286],{},"class MultiplyCalculator extends Calculator {\n@Override\nint calculate(int a, int b) {\nreturn a * b;\n}\n}",[14,288,289],{},"여기서는 객체에 따라 calculate() 동작이 달라진다.",[14,291,292],{},"Calculator calculator1 = new Calculator();\nCalculator calculator2 = new MultiplyCalculator();",[14,294,295],{},"calculator1.calculate(10, 20); \u002F\u002F 30\ncalculator2.calculate(10, 20); \u002F\u002F 200",[14,297,298],{},"반대로 동작이 항상 같고, 특정 객체의 상태도 필요하지 않다면 static이 자연스럽다",[14,300,301],{},"class CalculatorUtils {\nstatic int add(int a, int b) {\nreturn a + b;\n}\n}",[14,303,225],{},[14,305,306],{},"필드가 필요하다 -> 일반 메소드\n필드가 필요 없지만 객체마다 동작이 달라질 수 있다 -> 일반 메서드\n필드가 필요 업고 동작도 항상 같다 -> static 메서드가 자연스럽다.",{"title":38,"searchDepth":308,"depth":308,"links":309},2,[310,315,319,320],{"id":12,"depth":308,"text":5,"children":311},[312,314],{"id":20,"depth":313,"text":21},3,{"id":59,"depth":313,"text":60},{"id":78,"depth":308,"text":79,"children":316},[317,318],{"id":82,"depth":313,"text":83},{"id":109,"depth":313,"text":110},{"id":130,"depth":308,"text":131},{"id":166,"depth":308,"text":167},[322,323],"java","oop","2026-08-11 11:20:00 +0900","Java static 메서드, 일반 내부 클래스, static 중첩 클래스의 차이와 사용 기준을 정리한다.","md",null,"\u002Fjava\u002Foop\u002F2026\u002F08\u002F11\u002Fjava-static-nested-class\u002F",{"layout":330},"post",true,"5","\u002Fposts\u002Fbackend\u002Fjava\u002Foop\u002F2026-08-11-java-static-nested-class",{"title":5,"description":325},"Java 객체지향","posts\u002FBackend\u002FJAVA\u002Foop\u002F2026-08-11-java-static-nested-class",[338,339,340,341,342,343],"Java","Static","Nested Class","Inner Class","Method","Polymorphism","o40P01HDe0paWCyKfKUDgRJIlYYXjPbLe1y2qmbPPUM",1788744785081]