50 likes | 128 Views
This Java project demonstrates abstract classes and polymorphism using parent, teacher, and person classes. Implementing abstract methods and utilizing polymorphism for method calls.
E N D
People Application • Project name: People • Package name: org.notborder.people
Parent, Teacher and Person classes are abstract (추상) love() method in the Person class is abstract
추상 매소드 • 상위 클레스에서 정의된 추상 매소드를 추상 아닌 하위 클레스에서 반드시 구현해야
Polymorphism • Add Main class with main method • create ArrayList<Person> • create 1 object for each concrete class and add to the ArrayList • use ‘for’ loop to call ‘잔소리’, ‘love’ and ‘hit’ methods for all objects (use ‘instanceof’ operator test before calling the hit method)
Output • 잔소리method prints 하지 마라요 • love method prints 선생님: 숙재를 줘요for the Teacher classes, 엄마: 밥을 줘요 for the 엄마 class, and 아빠: 돈을 줘요 for the 아빠 class • hit method prints Please don't hit me, 아빠!, Please don't hit me, 엄마! and Please don't hit me, 선생님! for the relevant classes