Fruit is ripened ovary which is formed after fertilisation. Fruit's primary function is to aid in reproduction as it encloses the seeds, which contain the future generation of the plant in the form of embryo.
Fruit protects the seeds against desiccation and also protects them from other animals as immature fruits which contain immature seeds retain a bitter taste. Fruits become tasteful and edible only when the seeds get fully developed.
Fruits also aid in dispersal of seeds to distant places, in order to ensure that the plant species gets spread to new places. Some birds and animals eat fruits but cannot digest the seeds. They spread the seeds with their faeces.Some fruits explode to shoot up seeds to distant areas while some other have wings etc. mechanisms to get dispersed, along with the enclosed seeds, to new places. Dispersal of seeds to wide areas maintains proper spacing between the seedlings, thus reduces the competition between the seedlings for resources; introduces the species to newer areas; and also increases the chance of survival of the species as if a certain area encounters a calamity like fire or drought then the species survives in the form of the populations at distant places.