Gravity is one of the four fundamental interactions of nature. Gravity is the cause of the forces of attraction between bodies with mass.
According to the "law of universal gravitation of Newton", the mass of a body located at a point in space, is associated with a "gravitational field"; this field exerts a force of attraction on the other body at a distance from its center. The "gravity" or gravitational field strength of a body with mass M at a distance d is described by the following equation:
g = GM/d2
Where M is the mass of the body, d is the distance from the center of the body to the point and G is the "universal constant of gravitation".
The Sun is a body with a very large mass,, therefore, in the space surrounding it establishes a gravitational field which exerts a force on the earth and the other planets of the solar system; this force keeps planets in their orbits.
Albert Einstein described the "gravity" as a deformation of space-time caused by the mass of the celestial bodies. In either case, the mass of the bodies, is the cause of gravity.
In conclusion, the sun has gravity and the cause is the solar mass.
The Sun has an enormous amount of gravity, a product of its enormous amount of mass. It is that gravity that keeps the planets that form our solar system in their continuous orbit around the Sun. Think about the distance between the Sun and the dwarf planet, Pluto, which is over 3.6 billion miles. The amount of gravity required to keep a planet, even a very small one, locked into an orbit around itself requires a certain amount of mass, and only a star – and the Sun is considered a medium-size star – can exhibit that essential physical characteristic.
Gravity is a product of mass. It is a star’s gravitational pull that keeps it – an unbelievable amount of gaseous matter – in a unified structure with multiple layers. Stars are so large, and so massive (in terms of the matter comprising the star), that the amount of gravity they exhibit is sufficient to hold other massive objects like planets. Much of the Sun’s gravity is generated at its core, which has a density of 1.622 x 105kg/m3. In short, the density of the Sun’s core is astronomically high. It’s almost incomprehensible to those of us on Earth who aren’t physicists, let alone astrophysicists. In any event, suffice to say that the Sun’s core is incredibly dense and sufficiently hot so as to generate nonstop nuclear explosions. The Sun’s mass is 1.99*10^30. Earth’s mass is 5.97*10^24 kg.
[Reference https://www.physicsforums.com/threads/gravitational-force-between-sun-and-earth-moon-and-earth.235378/]. The huge disparities in relative mass allow for the Sun’s ability to keep its planets in a continuous orbit despite the effects of each planet’s individual gravitational pulls and on the inertia involved in something as massive as a planet moving through space.
The Sun accounts for over 99 percent of the solar system’s aggregate mass, with Jupiter accounting for most of the rest. [See http://earthguide.ucsd.edu/virtualmuseum/ita/08_1.shtml] The Sun’s mass is 333,000 times that of the Earth, so its gravitational pull exceeds the Earth’s by a wide margin. We know the Sun has a certain amount of mass and we know the relative value of the Sun’s mass to its planets. We know that gravity is a product of mass. We know that the planets orbit the Sun, not the other way around. Therefore, we know that the Sun has gravity, and that’s gravity dwarfs that of everything else in its solar system.
According to "Newton's law of Gravitation" - When two bodies having masses m2 and m2 are seperated by a distance d than the force they exert on each other is given by F = [G(m1)(m2)/d^2].
Now sun has enormous mass, let it be "M". Let there is another body with mass "m" at a distance "d" from it.
Force of Gravitation between them: F = [G(m1)(m2)/d^2]
But also force F = m x a
--> m x a =[G(M)(m)/d^2]
--> a = G(M)/d^2 [a = accelaration due to gravity]
Above relation proves that why does sun exerts gravity.