The answer is Cognitive Dissonance; Self-Perception.
"Cognitive Dissonance theory best explains attitude change while Self-Perception theory best explains attitude formation."
In Cognitive Dissonance Theory, an individual seeks consistency in his beliefs and behaviors. When a conflict happens between the two, there's a need for change. For example, a man who smokes cannot quit smoking even if he knows the bad effects to his health. To reduce the discomfort, he will justify his behavior, convincing himself that to quit smoking will just make him gain weight, which is also a health risk.
On the other hand, the Self-Perception Theory assumes that our actions are self-revealing. We use our behavior to know what we feel. For example, you aren't sure if you really like the new student in your class. But you always greet her and have small talk with her, and even let her borrow some of your books. Your behavior towards your new classmate will make you think that you probably like her.