--- id: java-inheritance title: "Java Inheritance" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["subclass", "superclass", "extends keyword", "μžλ°” 상속"] 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", "inheritance"] raw_sources: ["https://www.w3schools.com/java/java_inheritance.asp"] applied_in: [] github_commit: "" --- # [[Java Inheritance]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The choice between `protected` and `private` on a parent attribute directly determines whether inheritance "works" for that field β€” the source deliberately uses `protected` on Vehicle's `brand` and notes that `private` would have blocked Car from accessing it at all. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Subclass (child)** β€” the class that inherits from another. [S1] - **Superclass (parent)** β€” the class being inherited from. [S1] - **`extends`** β€” keyword used to inherit from a class. [S1] - **`protected`** β€” required (not `private`) if a subclass needs to access a parent attribute directly. [S1] - **`final` on a class** β€” prevents any class from extending it; attempting to do so is a compile error. [S1] - **Motivation** β€” code reusability: inherit attributes/methods of an existing class into a new one. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic inheritance: `class Vehicle { protected String brand = "Ford"; public void honk() { System.out.println("Tuut, tuut!"); } } class Car extends Vehicle { private String modelName = "Mustang"; ... } ... myCar.honk(); myCar.brand + " " + myCar.modelName;`. [S1] - Final class blocks inheritance: `final class Vehicle { ... } class Car extends Vehicle { ... } // error: cannot inherit from final Vehicle`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **protected ν•„μˆ˜μ„±**: brandκ°€ privateμ΄μ—ˆλ‹€λ©΄ Car ν΄λž˜μŠ€κ°€ μ ‘κ·Όν•  수 μ—†μ—ˆμ„ κ²ƒμ΄λΌλŠ” 점이 λͺ…μ‹œμ μœΌλ‘œ 강쑰됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” Vehicleβ†’Car 상속 κ΅¬μ‘°λŠ” λ‹€ν˜•μ„±(Polymorphism) μ±•ν„°μ˜ 직접적 μ „μ œκ°€ λœλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Subclass inheriting a protected attribute and a method (Java): ```java class Vehicle { protected String brand = "Ford"; public void honk() { System.out.println("Tuut, tuut!"); } } class Car extends Vehicle { private String modelName = "Mustang"; public static void main(String[] args) { Car myCar = new Car(); myCar.honk(); System.out.println(myCar.brand + " " + myCar.modelName); } } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[Java Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[Java Modifiers]], [[Java Polymorphism]], [[Java Super Keyword]], [[Java Abstraction]] - **μ°Έμ‘° λ§₯락:** 클래슀 κ°„ 속성/λ©”μ„œλ“œ μž¬μ‚¬μš© β€” λ‹€ν˜•μ„±/super ν‚€μ›Œλ“œ μ±•ν„°λ‘œ 직접 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” Java Inheritance (Subclass and Superclass) β€” https://www.w3schools.com/java/java_inheritance.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java Inheritance" page (Astra wiki-curation, P-Reinforce v3.1 format).