Вопрос

If we treat tree as an object then what will be its leaf and branches?
Similarly, if we treat dog as an object then what will be its legs,mouth and eyes?

Это было полезно?

Решение

A tree HAS a set of branches. Each branch HAS a set of leaves.

That is, (pseudocode)

class Tree {
    Branch[] branches;
}

class Branch {
    Leaf[] leaves;
}


class Leaf {

}

Similarly with the dog: a dog HAS a collection of eyes; it also has a collection of legs; and it has a mouth.

class Dog {
    Leg[] legs;
    Mouth mouth;
    Eye[] eyes;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top