First of all, schools can play a role by providing comprehensive sex education. At home, parents should be role models of appropriate behavior. They can also ensure that there are private spaces for the teenager. Moreover, promoting healthy hobbies and activities for the teenager can help them focus on positive things and avoid inappropriate behavior.
Good communication within the family is essential. Parents need to create an open and trusting environment where the teenager feels comfortable to talk about any issues or confusion they might have, rather than acting out inappropriately. Also, setting clear boundaries at home regarding privacy helps a lot.