Are cataracts inherited? Is there any way to prevent getting them?

Yes. Some are inherited. Cataracts are typically a natural aging process, but can avoid outside factors that accelerate their formation -- oxygenation (eye surgery), uv, radiation, meds, trauma, etc.
Some are. Some cataracts are inherited and are often associated with other congenital problems. The vast majority are caused by aging and hence are termed senile cataracts. Sunglasses and diets rich in antioxidants appear to be somewhat protective. For the genetic type, there is very little that can be done except for surgery.