Cutting an apple breaks open its cells. Oxygen from the air can now reach ingredients that were kept apart inside them.
An enzyme—a substance that helps chemical changes happen—speeds up the reaction. It produces materials that turn the cut surface brown.
The apple has changed color even though you just sliced it. Browning by itself does not mean the fruit is rotten.