What is the basis of grammaticality?
Accepted usage. Grammar of any language is based on how a native speaker uses a particular language to communicate. From sounds to mechanics all elements must be acceptable.
Grammaticality there is some difference as the first one, "in class", is a little bit ambiguous. "In class" can mean both "In a class" and "In the class" but unless the class is defined before that statement it usually means "In a class". "In the class" always needs to have the class defined otherwise it is drawing upon unknown knowledge.