Why would someone be self-righteous?

I knew this girl, who ALWAYS thinks she is in the right about everything. If she does something wrong, she looks embarrassed and tries to justify it with excuses but never apologises, but if someone else does something wrong she says they are bad people and she is the "good one." LOL. She tells others that "even though she's the youngest, she's always the most mature person in the room" (she's actually not that mature) and talks about how nice she is all the time and how everyone is always "doing her wrong."

She just can't see that she is also causing these "wrong" things to happen with her actions towards others. She always thinks she is in the right no matter what. She's always on some moral high-horse above everyone. Why are some people self-righteous like this?
Why would someone be self-righteous?
Post Opinion