Yep, that’s fine. The only caveat is this: If the class is big and the professor knows your son’s performance primarily through his tests and other grades, it’s not the same as if the prof actually knows HIM. Colleges are looking for some insight into how each applicant stands out in the crowd beyond the “numbers.” Granted, in many public high schools (and even in some private ones), teachers may not be able to provide this information either … or aren’t skilled enough in their writing to do so. Thus, admission folks are accustomed to reading references that say little beyond, “Jeremy is an A student who will succeed at the college of his choice.” But your son’s goal should be to select a recommender who knows more about him than just his GPA. So, no matter how well he’s doing in calculus, if the professor can barely match your son’s face to his name (or merely views him as “that quiet kid in the corner with the orange backpack and the 99”) then it’s not a wise choice.
Note also that if your son is applying to college through the Common Application, you may have some technical problems when it comes to “inviting” an outsider to write a reference. (This year’s new version of the Common App has spawned lots of snafus that didn’t exist before, and the corrections are still a work in progress.) If these obstacles exist–and seem insurmountable by deadline time–your son should provide the professor with a stamped envelope addressed to every college on his list and ask the prof to snail-mail the reference, making sure that your son’s full name and high school name are on every copy.