Considering 40 lacs as capital gains, investment can be made in following options to claim capital gain exemption:
1. One house property for 40 lacs
2. One house property for 20 lacs and another for 20 lac
3. One house property for 20 lacs and one land of 20 lacs ( construction of house is a must within 3 years,)
4. 20 lacs in a house property and 20 lacs in bonds.
There can be more combinations possible but the maximum no. Of house properties shall be 2. And such option of investment in 2 properties and claiming capital gain exemption is once in a lifetime option. If you have capital gain in future, you can invest in 1 residential house property and claim capital gain exemption.