Interior solutions of Einstein field equations for anisotropic spheres with variable energy density are obtained. The solutions for uniform energy density  and for radial pressure equal to zero  are particular cases of the present solution. With this solution we are also able to discuss an anisotropic gas sphere. Physically it explains larger red-shifts of different quasi-stellar objects. The results of the model have been used to explain the behaviour of a neutron stars and conclude that the maximum mass of a neutron star does not exceed two solar masses, which confirms the Chandrasekhar limit.