1. Boys often have trouble focusing in class.

2. Boys often have trouble focusing on class.

3. Boys often have trouble focusing on teaching in class.
==========================
Q1: Which one is grammatical?
Q2: Does #1 mean #3?

#1 is best.

#2 would work if you wrote "their classwork" instead of "class."

#3 is wordy. It's better to use #1.