๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java

[Java] ๋ถ€๋ชจ๋ฅผ ๋ถ€๋ฅด๋Š” ์˜ˆ์•ฝ์–ด, super

by ์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 2. 19.
๋ฐ˜์‘ํ˜•

โ–ถ ๋ถ€๋ชจ๋ฅผ ๋ถ€๋ฅด๋Š” ์˜ˆ์•ฝ์–ด, super

super ์˜ˆ์•ฝ์–ด๋Š” ํ•˜์œ„ ํด๋ž˜์Šค์—์„œ ์ƒ์œ„ ํด๋ž˜์Šค๋กœ ์ ‘๊ทผํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

this๊ฐ€ ์ž๊ธฐ ์ž์‹ ์˜ ์ฐธ์กฐ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ๊ณผ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.

โ€‹

์ƒ์œ„ ํด๋ž˜์Šค ์ƒ์„ฑ์ž ํ˜ธ์ถœํ•˜๊ธฐ

 

Customer ํด๋ž˜์Šค์— ์ƒˆ๋กœ์šด ์ƒ์„ฑ์ž ์ถ”๊ฐ€ํ•˜๊ธฐ

 

๋ช…์‹œ์ ์œผ๋กœ ์ƒ์œ„ ํด๋ž˜์Šค ์ƒ์„ฑ์ž ํ˜ธ์ถœํ•˜๊ธฐ

 

package inheritance;

public class CustomerTest2 {
	public static void main(String[] args) {
		VIPCustomer customerKim = new VIPCustomer(10020, "๊น€์œ ์‹ ");  // ํ•˜์œ„ ํด๋ž˜์Šค ์ƒ์„ฑ
	//	customerKim.setCustomerID(10020);
	//	customerKim.setCustomerName("๊น€์œ ์‹ ");
		customerKim.bonusPoint = 10000;
		System.out.println(customerKim.showCustomerInfo());
	}
}

<์‹คํ–‰ ๊ฒฐ๊ณผ>

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€