Burninghering's Blog
article thumbnail
3-3.객체 지향 핵심 - 상속에서 클래스 생성 과정과 형 변환
JAVA 2022. 1. 15. 00:56

1. 하위 클래스가 생성 되는 과정 하위 클래스를 생성하면 상위 클래스가 먼저 생성 됨 new VIPCustomer()를 호출하면 Customer()가 먼저 호출 됨 클래스가 상속 받은 경우 하위 클래스의 생성자에서는 반드시 상위 클래스의 생성자를 호출 함 Customer.java public Customer() { customerGrade="SILVER"; bonusRatio=0.01; System.out.println("Customer() call"); } VIPcustomer.java public VIPcustomer() { bonusRatio=0.05; salesRatio=0.1; customerGrade="VIP"; System.out.println("VIPcustomer() call"); } ..