First you need to do well in all your course works. Have a good attitude towards learning. Do not just accept what the professor tells you or what the book says. Try to answer the questions yourself first. If you cannot answer them by yourself, then go to ask the professor.
Professors usually encourage students to ask questions, during the class or during office hours.
Professors tend to like dynamic students who think independently. Having a good interaction with your professor during a course is a good way to establish a good relationship with faculty members. This could be very helpful for your later application of academic jobs. Remember that when you apply for jobs, you need to have the support of several professors in your department, not just your own advisor. It is also a good idea to keep other faculty members informed of what you are working on in your thesis.