You were redirected here from 정규식.

Polymorphism

class MyOwnCoffee
{
	public static void main(String[] args) {
		Coffee myCoffee = makeMyCoffee();
		enjoyTea(myCoffee);
	}

	//① 반환형(Return type)과 반환값(Return value) 주목!
	private Drink makeMyCoffee() {
		int tumblerSize = 420;
		int waterRatio = 3;
		int coffeeRatio = 1;

		return new Coffee(tumblerSize, waterRatio, coffeeRatio);
	}

	//② 매개변수 형(Parameter type) 주목!
	private void enjoyTea(Tea tea) {
		Coffee myCoffee = (Coffee) tea; //③ Down casting!
		myCoffee.makeCoffee();

		do {
			myCoffee.sip();

			if(myCoffee.empty()) {
				myCoffee.refill();
				break;
			}
		}
		while(true);
	}
}

polymorphism.txt · Last modified: 2021/02/07 03:15 by 127.0.0.1