• Inheritance, Polymorphism

    Written by Jonas Altrock (ew20b126@technikum-wien.at).


    The third exercise is about class inheritance and the polymorphism it enables. Polymorphism means "many forms", and is one of the core ideas of object-oriented programming. The idea is that we can write code for a base class, and other code can create extensions for our classes, but still use the code we wrote, without modification. Our code accepts many shapes, because we can be certain that the objects behave like something we know (the base class).

    We are asked to override the Object.toString method that exists on all classes (because all classes inherit implicitly from Object). This way all our entity objects can be used in expressions where a String would be expected, for example concatenation with another string.

    We also have to implement two sub-classes of our Event class: MusicLandscape.entities.Concert and MusicLandscape.entities.TVShow.

    The most interesting part of the assignment is the polymorphic call to the impact() method in Event.toString.