I was wondering if I can model the relationship between the two class hierarchies below, in the way that I did:

The code that would represent the meaning of this would be something like:
public abstract class Car
{
protected Engine engine;
}
public class StreetCar extends Car
{
public StreetCar()
{
engine = new StreetEngine();
}
}
…and similarly for the class OffroadCar, it would do something like engine = new OffroadEngine(). I have not included anything about the accelerate() method, it’s not relevant.
I just want to know if the composition is modeled correctly or if it’s redundant or even wrong to add that many composition arrows.
Before answer question, this is one of those cases, where is a good idea to split hierarchy relationships from composition relationships, as if they where different kind of diagrams.
Note: I added Engine to the diagram, as “protected”, and “Class” prefix, to avoid confusing.
(1) Composition Diagram
An object of “CarClass” its composed by 1 single object of “EngineClass”.
(2.1) Inheritance Diagram
An object of “CarClass” may have child classes, upon certain scenario.
(2.2) Inheritance Diagram
An object of “EngineClass” may have child classes, upon certain scenario.
3 Answer
Now, this is a case, where a class has an unleast one composing member, and its type may be overriden, when the main class its overriden. This is sometimes called the “Paralell Hierarchy Software Pattern” or “Dual Hierarchy Software Pattern”.
You have only mention 2 subclasses of each main class, but, in reality, there could be more.
Usually I make charts like this 2 ways. One, I make the first diagram, adding a comment, that indicates that its this case.
3.1 Main Paralell Hierarchy Diagram
The second case, its when both classes has child classes that both add members.
3.2 Additional Paralell Hierarchy Diagram
I may add additional diagrams, if necesarilly.
4 Show me the code
In order, to manage this “parallel” hierarchies, usually, the creation of the composite members its managed by a overriden method.
Cheers.
P.S. Can I, ur, haz a Fishburguer ?