super
- μ°Έμ‘°λ³μ super
-
κ°μ²΄ μμ μ κ°λ¦¬ν€λ μ°Έμ‘°λ³μ
-
λΆλͺ¨ ν΄λμ€ λ©€λ²μ μμ ν΄λμ€ λ©€λ² μ΄λ¦μ΄ κ°μ λ super ν€μλ μ¬μ©ν΄ ꡬλ³
-
μΈμ€ν΄μ€ λ©μλμμλ§ μ¬μ© κ°λ₯ (ν΄λμ€ λ©μλμμ μ¬μ© X)
-
- μμ±μ super()
-
λΆλͺ¨ ν΄λμ€μ μμ±μλ₯Ό νΈμΆν λ μ¬μ©
-
λΆλͺ¨ ν΄λμ€μ λ©€λ²λ₯Ό μ΄κΈ°ννκΈ° μν΄μλ μμ ν΄λμ€μ μμ±μμμ λΆλͺ¨ ν΄λμ€μ μμ±μκΉμ§ νΈμΆν΄μΌν¨ > λΆλͺ¨ν΄λμ€μ μμ±μλ₯Ό λͺ μμ μΌλ‘ νΈμΆνμ§ μμΌλ©΄ μμ ν΄λμ€μ μμ±μ 첫 μ€μ μ»΄νμΌλ¬κ° μλμΌλ‘ λν΄νΈ μμ±μ μΆκ° > λΆλͺ¨ ν΄λμ€μ λ©€λ²λ₯Ό μ΄κΈ°ν ν μ μλλ‘ ν¨
-
but, λΆλͺ¨ ν΄λμ€μ κΈ°λ³Έ μμ±μ μλ€λ©΄ μ€λ₯ > λͺ μμ μΌλ‘ μ μΈν΄μΌν¨
-
- ex)
-
Customer.java
public class Customer { protected String customerName; protected String customerGrade; protected int bonusPoint; public Customer(String customerName) { this.customerName = customerName; customerGrade = "SILVER"; } public String showCustomerInfo() { return customerName + "λμ λ±κΈμ " + customerGrade + "μ΄λ©°, 보λμ€ ν¬μΈνΈλ " + bonusPoint + " μ μ λλ€."; } }
-
VIPCustomer.java
public class VIPCustomer extends Customer{ public VIPCustomer(String customerName) { super(customerName); customerGrade = "VIP"; } public String showCustomerInfo() { return customerName + "λμ λ±κΈμ " + customerGrade + "μ΄λ©°, 보λμ€ ν¬μΈνΈλ " + bonusPoint + " μ μ λλ€."; } }
-
Main.java
public class Main { public static void main(String[] args) { Customer customerA = new Customer("λ°νλ"); customerA.bonusPoint = 1000; System.out.println(customerA.showCustomerInfo()); VIPCustomer customerB = new VIPCustomer("κΉλ°λ€"); customerB.bonusPoint = 15000; System.out.println(customerB.showCustomerInfo()); } }
-