Here's why:
* The moon reflects sunlight. It doesn't produce its own light, so it's visible when the sun is shining on it.
* Stars are very far away. Their light takes a long time to reach us, so we see them even during the day. However, the sun's light is so much brighter that it overwhelms the faint light from stars, making them invisible in the daytime.
Therefore, you can see the moon and stars together at night, when the sun is below the horizon and the sky is dark enough to reveal the stars. You might also be able to see a few bright stars close to the moon, even in the daytime.