For the shadow to be visible, we always require two things. 1. An opaque object 2. Source of light. But ball and table in a dark room, building at night will not cast shadow as there is no source of light. Tree is an opaque object and on sunny day, sunlight is also there. So we can see a shadow in this case.