The lens focuses on the subject as soon as the shutter button is depressed. Most of the time it works, but occasionally it will focus on the wrong part of the image, particularly if the subject is off-centre.
Auto-focus is wonderful, but photographers tend to rely on it too much without considering the alternative. Some cameras even have as many as ten or eleven focusing points - surely nothing can go wrong now? Well when it does, there is always face recognition, but I want to photograph a dickybird!
Automation can encourage laziness. We tend to overlook what some of us learnt many years ago that is still useful today. Digital Single Lens Reflex Cameras do have a facility to focus manually and if the photographer has a few seconds to spare, it is much the preferred way and usually more accurate.
Auto-focus has valuable uses, especially action, but with focussing and many other aspects of photo-technique, don't forget the alternative, particularly if it is the traditional way.

Focusing