In the first line? Tough one. I would say that a certain amount of luck is involved. Something akin to winning the lottery. For instance, “Call me Ishmael”. —Herman Melville, Moby-Dick (1851). That opening sentence doesn’t really do anything to reach out and grab the reader, yet it is one of literature’s most famous lines. Why? Partly the name. It’s unusual. The other, we want to know who he is, and why we should care?
Many times, a writer will dive right into an action sequence to get the reader on the hook. “They shoot the white girl first”. —Toni Morrison, Paradise (1998). That’s a pretty brash statement that your mind begs to know more about.
Other times it is a statement so profound that it sticks with the reader, calling them in. “In our family, there was no clear line between religion and fly fishing”. — Norman Maclean, A River Runs through It (1976). A statement about two things that most people would consider to not have anything remotely in common.
I believe that most of the time, writers don’t realize the impact of an opening sentence until it’s already on the paper. Sure, we all try to make it memorable, but some of it comes down to sheer luck.
If you want to connect with your readers, it’s important to know your audience, and yourself. Each of the examples I offered are statements from writers whose writings were not just words on a page, the words they wrote were a part of them. Meaning, they had a connection to what they were writing. For an opening sentence, paragraph, or chapter, you need to be invested in what you write.
Know yourself and your audience, the rest is up to chance.