Every university has guards for the safety of students. If anyone can enter the campus at will, then students are not very dangerous at school. Generally speaking, you can enter as long as you explain the situation to the doorman and register your personal information. You can enter the school library and study room, but you should observe discipline on campus and don't do anything illegal.
If the university class is a large class with several classes together, you can also mix in to attend classes. If it is a small class with only 20 or 30 people, it will be very embarrassing to get in. As long as the teacher doesn't call the roll, it should be ok. If anyone asks, it's the wrong classroom. The university classroom is not fixed. This is very common.
Extended data:
Generally, schools are closed to tourists. University is a place to study, so be quiet. If it is open, it will affect students' early study, and people can't study quietly. Most university campuses are also open to the outside world. During the opening of the campus, visitors can freely enter and visit the campus environment.
Of course, some schools run by scientific research institutions also need permission. There are also some schools that have to swipe their cards in order to enter the campus safely. Such schools are not allowed to enter casually. However, general public universities can enter, but it is not recommended to join the group, and it is still possible to visit.