My teacher told me that sun is a black body but after reading at various sites whre they say that sun is not a black body but has black body radiations because it cannot absorb all radiations.
Here is the measured radiation from the sun
It is fitted with a black body curve, at the top of the atmosphere (yellow) and even though it is evident that there are deviations from the theoretical black body, it is still a good approximation.
Generally all bodies radiating are approximated with a black body spectrum. If it fits well, that means that it also absorbs the same type of spectrum, if it fell on it. The deviations are due to the differences stated in the other answer.
It is not a sufficient condition for a blackbody to be perfectly absorbing at all wavelengths. The Sun satisfies this condition pretty well. The proposed blackbody must also be in thermal equilibrium. That is, its energy level distributions, particle speed distributions (etc.) must be in equilibrium and characterised by a single temperature. Furthermore, the radiation field must also be in equilibrium with the matter at the same single temperature.
Whilst for the interior of the Sun, this is a very good approximation, near the surface it is not, because radiation can escape and the temperature changes with depth on a length scale comparable with the mean free path of the photons. As a result it is better to think of the Sun as emitting blackbody radiation from different layers at different temperatures.