Objects that are less dense than water will float and more dense than water will sink when we put the objects in the water. The apple floats because the apple is less dense than water. Less dense object when it is immersed in the water will displaces an amount of water which is equal to the amount of that object.
The air pockets present in the cells of an apple will capture enough air (oxygen) and make the density lesser than the water. The objects more dense than water will sink because they do not displace the water when it is fully submerged (resting under the water). A pear is denser than water and has higher water content.
This may not be true that all apples should float and pears should sink. This is a general rule. Most of the apple will float and pears will sink in the water.
The apple has the capacity to absorb oxygen after it is plucked from the tree. This will make the apple to stay fresher for longer days than other fruits.