These are the two ways of learning. Which is better among the two. Universally we can't say one among the two is best. We have to decide based on our interest and time availability. Some people will put in more efforts by using their leisure time. But some can concentrate if there is a system of attending a class at a dedicated time. Here the attitude of the individual will differ.
There are people who studied on their own without going to any class or attending any online course and successful in their career. Some people even after attending the classes couldn't achieve much. In my opinion, the interest and commitment of the individual play an important role than other issues.
Online courses are recent advancements and these days they have become very prominent and many people are pursuing their career through these online courses.