When you eat food the food is then cut down into micro nutrients which is further carried by blood to the whole body. Some food is stored in the body as fat and some is carried through the blood. When you are performing any activity the body will survive by consuming the stored energy that are fats to continue its function. If the food you eat are stored by the body as fat and you don't perform any activity it will remain there and with the passage of time by eating more and having no activity the body will gain the weight in the form of extra fats.
image credits: (sites.jmu.edu/gbio103/files/2015/12/fast-vs-slow-metabolisms.jpg)
Gain of weight is totally dependent on your body metabolic system. Metabolism is like an engine in the body that will provide power to each organ to perform its function. The energy will be the food that you consume like a fuel for the engine of a car, If your metabolic system is healthy you will be unable to gain weight so easily because all the food that you eat is consumed by the organs effectively and you cant store any type of fat in your body. Now if your metabolic system is slow, not healthy than your body will tend to store food as fats and your organs will not perform efficiently.
Image credits: healthjournalonline.files.wordpress.com/2013/01/junk-food.jpg
There are two categories, those having healthy metabolism and those have metabolism damaged. The first category, with healthy metabolism they will not gain weight because fats are not being stored, These are people are very lucky in my opinion, If they want to gain weight they have to eat much more above the caloric surplus and then hitting the gym to perform the weight training because the weight training will tears the muscle and that muscle will recover and grow by consuming that extra right type of food. Now it does not mean that you have to eat each and every thing burgers, cold drinks, fast food, processed food , and oil stuff, for that no and never you have to eat the right type of food having high amount of proteins in it for recovery and growth of muscle.
Image credits: (t-nation.com/system/publishing/articles/10002863/original/Fix-Your-Metabolism-with-Weight-Training.jpg?1430169340)
The other category those having the metabolism slow and damaged will gain weight easily. For them the best way is to reduce the amount of daily caloric intake means eat less but divide that food into the chunks means eat after every 1 to 2 hour but eat the right food don't go for processed, fast food, sugary drinks and oily stuff eat clean through out the day and hit the weight and resistance training for toning the muscle of body and getting it in to shape by burning fat.
image credits: www.weightworld.uk/images/wwuk-metabolism-infograph.jpg