"Have a nice class." Is this sentence correct?
Solution 1:
It's grammatically correct and doesn't strike me (a native speaker from Illinois) as odd. It's nowhere near as common as things like "have a nice day" or "have a good trip" are, but I wouldn't find it at all strange if someone said it to me. Now that I'm thinking about it, my intuition tells me that "Have a good class" would be slightly better, but the difference to me is not a very important one.
I confess that I'm not necessarily able to justify this stance, though. It's tough to check this using Google because "have a nice/good class" results in hits like "I have a nice/good class. Everyone is friendly" and other things that are not what we need. It's also tough to check it using a corpus search because it's such a specific phrase to look for. In COCA (the Corpus of Contemporary American English) I found no instances of "Have a nice class" and only one instance of "Have a good class"--and that one example is (a) kind of weird and (b) comes from an author who appears to be a non-native speaker residing in Turkey. Here is the example:
In the observations and interviews conducted, it was seen that the initial verbal stimuli used by most teachers at the beginning of class to grab students' attention included the same greetings everyday [sic]: 'Hello children, good morning, stand up, sit down, have a good class'.
(If teachers are saying that to their own students about the class that they, the teachers, are about to teach, that's strange.)
For what it's worth, when someone asked about "Have a good class" in a similar forum see here), the native speakers seemed to feel iffy about it, at best. One person suggests that "Enjoy your class" would be better, but I share the intuition of the other person who disagrees and says that that option (kind of) sounds sarcastic. This is possibly because it sounds a little formal compared to "Have a good/nice X."
I somehow still personally feel that "Have a good class" is fine and is the best option or that it's a tie between "Have a good class" and "Have a nice class". I dislike relying on intuition and I'd feel more confident if I could find examples uttered by native speakers, but it's not something that's likely to show up in a corpus. Even MICASE (the Michigan Corpus of Academic Spoken English, consisting of data collected at the University of Michigan) focuses on things like class meetings and study sessions. "Have a good class" is something you're likely to say during hallway chitchat with a friend right as before their class begins--a situation unlikely to be recorded even when you have linguists running around the school collecting data. This might remain a mystery, then.
Solution 2:
The reason this doesn't quite sound natural, I think, is that with "Have a nice X", X is usually a period of time.
Eg with "Have a nice day", "I hope you have a nice time", "Have a nice holiday!" etc, "day", "time" and "holiday" are used in the sense of the period of time. (see also the insulting "Have a nice life" which means "I don't want to ever see you again")
Some of these words have multiple senses in which they can be used: "Holiday" for example can be used to describe a two-week period where you're not in work, or it can be used to describe the specific thing that you did, eg go to Spain. "Have a nice holiday" refers to the time period sense of the word.
The word "class" doesn't as easily fit into this usage. Yes, the class will last for a certain period of time (an hour, say), but we don't usually refer to the time period itself using the word "class", which refers more to the activity - what you do in the time.
"Enjoy the class!" would be a more natural thing to say, as they're (hopefully) enjoying the activity, rather than the time period.