There is more to it than just that. For example you can have a class and an id for a div. The id attributes will overwrite the class ones. And some other fun rules too!
No, that's specificity (an entirely different beast, and one that can be considerably harder to work with). Inheritance would be styles for a P tag applying to a child I tag.