Yes pneumonia is very contagious and you should avoid contact with anyone who has pneumonia as it can spread pretty quickly.
Pneumonia can be deadly so you really want to avoid your chances of getting it. If you do go near someone with pneumonia you should wear a mask.
But it's best to just avoid being around them if they're in the hospital with pneumonia.