I don't understand why AbstractRobot class should be an abstract one where it contains 2 implemented methods. I acknowledge at the same time I have quite big problems with fully understanding all aspects of abstractions in OOP programming - plenty of hard time still before me :)
AbstractRobot being an abstract class
Musisz się zalogować, aby dodać komentarz
6 listopada 2021, 22:29
Task1328: The AbstractRobot class contains an abstract method, so the class must also be abstract. This abstract method can be implemented later in the Robot subclasses as desired. However, an abstract class can contain also an implemented method! The program designer obviously intended the attack() and defend() methods to be the same in all Robot subclasses. He/she therefore implemented these two methods in the abstract class so that descendants could inherit a ready-made method. For example, if we had more than one such class: RobotBoss implements AbstractRobot RobotWorker implements AbstractRobot RobotLooser implements AbstractRobot then the objects of these classes would be able to use the inherited defend() and attack() in the same way.
18 listopada 2021, 06:26
Thanks Gellert for your response :)