--- id: java-constructors title: "Java Constructors" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["자바 생성자"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["java", "programming", "w3schools", "oop", "constructors"] raw_sources: ["https://www.w3schools.com/java/java_constructors.asp"] applied_in: [] github_commit: "" --- # [[Java Constructors]] ## 🎯 한 줄 통찰 (One-line insight) Every class gets a constructor whether you write one or not — if you don't declare one, Java silently generates a default one, but that hidden default can't set custom initial values, which is the practical reason to write your own. [S1] ## 🧠 핵심 개념 (Core concepts) - **Constructor** — a special method that initializes an object; runs automatically when an object is created. [S1] - **Naming rule** — the constructor's name must match the class name exactly. [S1] - **No return type** — a constructor cannot declare a return type, not even `void`. [S1] - **Implicit default constructor** — Java auto-generates one if none is written, but it can't set custom initial values. [S1] - **Constructor parameters** — like methods, constructors can take parameters used to set initial attribute values. [S1] ## 📖 세부 내용 (Details) - Basic constructor: `public class Main { int x; public Main() { x = 5; } public static void main(String[] args) { Main myObj = new Main(); System.out.println(myObj.x); } } // Outputs 5`. [S1] - Constructor with one parameter: `public Main(int y) { x = y; } ... new Main(5); // x = 5`. [S1] - Constructor with multiple parameters: `public Main(int year, String name) { modelYear = year; modelName = name; } ... new Main(1969, "Mustang"); // "1969 Mustang"`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **기본 생성자의 한계**: 명시적으로 생성자를 작성하지 않으면 Java가 자동 생성하지만, 이 경우 초기값을 커스터마이즈할 수 없다는 점이 강조됨. [S1] ## 🛠️ 적용 사례 (Applied in summary) 현재 발견된 실제 적용 사례가 없습니다 — 자동차 모델(연도+이름)처럼 여러 초기값을 한 번에 설정하는 표준 패턴이다. [S1] ## 💻 코드 패턴 (Code patterns) Constructor with multiple parameters (Java): ```java public class Main { int modelYear; String modelName; public Main(int year, String name) { modelYear = year; modelName = name; } public static void main(String[] args) { Main myCar = new Main(1969, "Mustang"); System.out.println(myCar.modelYear + " " + myCar.modelName); } } ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.90 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[Java Tutorial]] - **관련 개념:** [[Java Class Methods]], [[Java This Keyword]], [[Java Modifiers]] - **참조 맥락:** 객체 초기화 메서드 — this 키워드 챕터로 직접 이어짐(파라미터명 충돌 해결). ## 📚 출처 (Sources) - [S1] W3Schools — Java Constructors — https://www.w3schools.com/java/java_constructors.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java Constructors" page (Astra wiki-curation, P-Reinforce v3.1 format).