20 students represent 100% of the class, to find how many students are 40% of the class, we can use the next proportion:
[tex]\frac{20\text{ students}}{x\text{ students}}=\frac{100\text{ \%}}{40\text{ \%}}[/tex]Solving for x,
[tex]\begin{gathered} 20\cdot40=100\cdot x \\ \frac{800}{100}=x \\ 8=x \end{gathered}[/tex]8 students have a pet