========================================================
Explanation:
Let's say the teacher pulls the two boys out of the line, and stands in their place. So we have 5 girls and 1 teacher making 6 people total.
There are 6! = 6*5*4*3*2*1 = 720 different permutations here. Order matters. This involves the teacher, so let's have him/her step out of the line and have the two boys replace the teacher's position. This guarantees the boys stick together. For any permutation, we have 2 different ways to arrange the boys. So we have 2*720 = 1440 different ways to arrange the students so that the two boys are next to each other.
This is out of 7! = 7*6*5*4*3*2*1 = 5040 different permutations overall (we're arranging 5 girls+2 boys = 7 people).
The probability we're after is going to be 1440/5040 = 2/7
--------
Or you could see it like this
1440 = 2*6!
5040 = 7! = 7*6!
So,
1440/5040 = (2*6!)/(7*6!)
1440/5040 = 2/7