I have Student class. The student has a grade. Teacher class can change the student's grade. Other classes (i.e., parent class) cannot do that. I think I get the part about how to change another class's property (please correct me if I'm wrong), but how to make sure that only the Teacher class can change the grade?
class Student {
grade = 'A';
changeGrade(grade) {
this.grade = grade
return `the new grade is ${this.grade}`
}
}
class Teacher {
changeStudentGrade(student, grade) {
return student.changeGrade(grade)
}
}