In English you can ask others “which class did you have?” when you randomly run into a friend at university who is not following the same classes that you do.
But notice that in Korean they don’t use the verbs “to have” or “to attend” in this situation. Instead they use “to listen/hear” ~ 듣다
무슨 수업을 들었어요? ~ which class did you have? (literally “which class did you listen to?”).