God knew the answer to this question. He asked it in order to help Adam to confess that he had disobeyed God.