Attitude formation occurs in a person through a variety of ways. Attitudes and behaviors start forming the day we are born and our environment is the main stimulus from which we learn. Attitudes can form from classical conditioning.
An example would be a child seeing their parent frown when they encounter a homeless person. This action and the stimulus of the homeless person form an association in the child's mind and they may develop a general negative attitude about homeless people.
Another way in which attitudes can form is by instrumental methods. This would be when someone is praised for endorsing an 'appropriate' attitude and punished for having an 'inappropriate' attitude. Biases and prejudices are often learned this way.
Attitudes can also be formed by observations of the people and environment. Observational attitude formation can be direct (such as observing parents' or peers' behavior) or indirect (observations of media).