I agree with the answer by Kristof, just to expand on their suggestion to get to know the person. I would take extensive notes in class, read the book, and come up with a lot of questions. I would try to answer them on my own, but some of them I could not, even after more than one try (this is pretty important).
I would then go to the professor's office hours and ask the questions, that I had previously written down. This built up a rapport, let me ask intelligent questions without having to rely on being confident and eloquent because I was initially nervous, and also helped me learn the material.
I'll be honest: with some professors I never got over being nervous. But to a person, they remembered me, respected me, and helped me get into graduate school because they saw that I cared enough to read over their lecture notes, the text books, and to write down good questions to bring them to their office hours.
Confidence comes with time, sometimes not until graduate school or you are a professsional in your field, frankly. What is important is gaining competence, and knowledge, and experience. With those, confidence will follow.