Your classmate's words probably tell you why one side of this right triangle is equal to 4 (that is, half the length of a cube).
Because the ball is placed on the top of the cube (very stable, no external force), the center of the ball must be in a straight line with the center of the cube. So when you draw a picture, the right-angled side of the triangle passes through the center of the cube, so the other right-angled side is half the length of the side.