Нow to add a student to the group? Как добавить студента в группу? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Нow to add a student to the group? Как добавить студента в группу?

I have two classes: Students and Group. I need to create an object and add it to the group. Tell me, please, how to implement this method.У меня есть два класса: Студенты и Группа. Я должна создать объект и добавить его в группу. Подскажите, пожалуйста, как реализовать данный метод.

29th Sep 2017, 8:33 PM
Alexandra Shin
Alexandra Shin - avatar
1 Answer
+ 3
Without knowing at least your classes interfaces, that's quite impossible to answer you accuratly ^^ In a generic way, you instanciate object with the 'new' keyword: var stud_instance = new Students(/* maybe constructor require some parameters*/); var stud_group_instance = new Group(/* parameters */); ... and probably the 'Group' class provide a method to add 'Student' object to the group instance, with something like (probably a different method name, or just lucky ;P): stud_group_instance.add(stud_instance);
30th Sep 2017, 1:59 PM
visph
visph - avatar