super() 키워드
형변환
Customer.java
public class Customer {
protected int customerId;
protected String customerName;
protected String customerGrade;
int bonusPoint;
double bonusRatio;
public Customer(int customerId, String customerName) {
this.customerId = customerId;
this.customerName = customerName;
customerGrade = "SILVER";
bonusRatio = 0.01;
System.out.println("Customer(int, String) call");
}
public int calcPrice(int price) {
bonusPoint += price * bonusRatio;
return price;
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerGrade() {
return customerGrade;
}
public void setCustomerGrade(String customerGrade) {
this.customerGrade = customerGrade;
}
public String showCustomerInfo() {
return customerName + "님의 등급은 " + customerGrade + "이며, 보너스 포인트는 " + bonusPoint + "입니다.";
}
}
VIPCustomer.java
public class VIPCustomer extends Customer {
private static int agentID;
double salesRatio;
public VIPCustomer(int customerId, String customerName) {
super(customerId, customerName);
customerGrade = "VIP";
salesRatio = 0.05;
bonusRatio = 0.1;
System.out.println("VIPCustomer(int, String) call");
}
public int getAgentId() {
agentID++;
return agentID;
}
}
CustomerTest.java
public class CustomerTest {
public static void main(String[] args) {
Customer customerKim = new VIPCustomer(10020, "김유신");
customerKim.bonusPoint = 10000;
System.out.println(customerKim.showCustomerInfo());
}
}