You need to pay attention in a class. Don't start chatting with your peers/friends when the teacher turns their back to you. Even better, don't associate with distracting people. You should realize that the people in your class play an important role in how everybody progresses. However, if you are a good student you will do better and achieve your goals. Your friends will be there for you at that time, if they are trustful and of a good reputation. At home, study and do your homework in a place that doesn't make you sleepy. It is advisable to have a dedicated study table or desk. Don't do your study work on the bed or in front of the TV, radio, stereo, etc. That would be pointless because you are meant to be thinking about your studies.