The correct answer is: Yes, because the trees in the sample are chosen randomly. The sample size also appears to be large enough to avoid bias.
The key factors that make the farmer's generalization valid are the random selection of the trees and the relatively large sample size, which helps to ensure that the sample is representative of the larger population of apple trees. As long as the apples from the sampled trees are tested for sweetness, the farmer can make a reasonable generalization about the sweetness of apples from all the trees on the farm.