Can I share a crystal between two AT89S52? Is this method correct?
You can connect XTAL2 (clock OUT) of the master chip (the one with the crystal) to XTAL1 (clock IN) of the slave chip and leave XTAL2 (clock OUT) on the slave chip open. 

This should work if the chips are close together. If you are running them over a distance a buffer from the XTAL2 output of the master would be a good idea. 

Or (better) use a crystal oscillator rather than a raw crystal and drive both chips with the external clock (XTAL1 and each, leave XTAL2 open on both). Pretty cheap, guaranteed stable and start-up and good drive capability. 

The code would not change, assuming the clock frequency is the same as what the programs were designed for. 

Edit: You should slightly reduce the load capacitor on the XTAL 2 line to account for the increased capacitance of the second input. 5pF is about right. Not important if you don't care about the exact clock frequency.