Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Застрял на добавлении детей в список экземпляра класса. #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

mangoost81
Copy link

Не получается добавить детей экземпляру класса.
Работает только если не выводить в терминал метод ToString.

import java.util.List;

public class FamilyTree {
List<Human> list;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поля класса почти всегда приватны



FamilyTree familyTree = new FamilyTree();
familyTree.list = new ArrayList<>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А было бы поле приватно и такая строчка была бы невозможной. В данном случае вы нарушаете инкапсуляцию. Только класс должен решать как ему использовать свои поле. Извне это должно быть невозможно

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants