Class relationships: Correct Solution


Consider the follow class declarations:

public class Dapir extends Karkass {
    public byte[] getDaLe() {
        ...
    }
}

public class Karkass {
    public List<String> getMusm() {
        ...
    }

    public List<String> getIcilt() {
        ...
    }
}

public class Mochost {
    public List<String> getMiiss() {
        ...
    }
}

public class Tisloss {
    public List<Dapir> getPsauls() {
        ...
    }

    public Mochost getNeSnir() {
        ...
    }
}
  1. Draw a diagram showing the class relationships.

    You only need to diagram the classes listed above. You only need to show the name of each class; do not show their methods or properties.

    Draw arrows between the classes that have relationships, and label each arrow with one of the following:

    Make sure your arrows point in the correct direction!

    Solution

  2. Given the following variable:

    Tisloss oss

    ...and the following method:

    public void process(List<String> item)

    ...write code to process the icilt of the first psaul of oss.

    Solution

    for (Dapir psaul : oss.getPsaulsList()) {
        process(psaul.getKarkass().getIcilt());
    }

Related puzzles: