Search code examples
oopinheritanceumlclass-diagram

Do associated classes of a subclass inherit the superclass?


I'm trying to understand how inheritance with association work between the superclass and its subclasses. Here are the classes with their relationships:

Classes

my question here if I created an object from class C, will it inherit also from class A as below? and why?

Objects


Solution

  • No. It won't inherit anything. B inherits from A so C will see a B with operations/attributes inherited from A.

    If I (class C) use a cleaning device B that inherited from Sponge (A) I will see/use a soft cleaning device. If B inherited from steel it would be steel wool. If inherting from sand it would be sand paper. All cleaning devices with different usability depending from where they inherit. But I wouldn't change in any way. Only the way I would "clean" things. (I know, a horrible example)


    N.B. As @www.admiraalit.nl commented your object diagram does not match the class diagram.