To solve this problem, simply use one variable to represent the number of students in each of the 2 classes.
1st class - X = no of students
2nd class - X + 6 no of students
Both classes : X + X + 6 = 50
2X + 6 = 50
2X = 44
X = 22.
1st class - X = 22 students
2nd class - X + 6 = 22 + 6 = 28 students.
There are 28 students in the larger class.