Let boy be denoted by $B$ and girl by $G$. If a family has two children, then there are the following possibilities for their kids $$BB,BG,GB,GG,$$ each with equal probability, e.g., $P(BB) = P(BG) = 1/4$.
Now, it should be clear for part A, that all we know is that the family is picked randomly from families that are $$BB,BG,GB.$$ Now, the probability that they have two boys is $$P(BB|BB\cup BG \cup GB) = \frac{P(BB\cap (BB\cup BG \cup GB))}{P(BB\cup BG \cup GB)} = \frac{P(BB)}{P(BB\cup BG \cup GB)} = \frac{1/4}{3/4} = \frac{1}{3}.$$
Now, in part B, we have something simlilar, but slightly different. What we have is that we saw a child and it's a boy. Now, the underlying assumption is that we randomly selected a child from the parent's two children. Thus, we have two equally likely scenarios, either we saw child 1 and it was a boy, or we saw child 2 and it was a boy. Let us focus on the former, and note that the probabilities are the same. We note that the event that "child one was a boy" is $BB \cup BG$.
$$P(BB|\text{child one was a boy}) = \frac{P(BB \cap (BB,BG))}{P(BB \cup BG)} = \frac{P(BB)}{P(BB \cup BG)} = \frac{1/4}{2/4} = 1/2.$$ Now, this happened with probability $1/2$ so the total probability that the family in part B has two boys is $$P(BB|\text{(child one was selected AND a boy) OR (child two was selected AND a boy)}).$$ Because it can't happen that child one was selected and child two was selected, these two events are disjoint, hence the probability is equal to $$P(BB|\text{child one was selected AND a boy)} +P(BB|\text{child two was selected AND a boy}) \\ =P(BB|\text{child one was a boy})P(\text{child one was selected}) \\ +P(BB|\text{child two was a boy})P(\text{child two was selected})\\ = \frac{1}{2}\cdot \frac{1}{2} + \frac{1}{2} \cdot \frac{1}{2} = \frac{1}{2}.$$ Where the first equality comes from the fact that whether or not child one was selected was independent of the family composition. Now, this was a bit wordy, but I hope it is helpful in its own right.
Note, throughout it is assumed that you know that a conditional probability of event $A$ given event $B$, denoted $P(A|B)$, is given by $$P(A|B) = \frac{P(A,B)}{P(B)}.$$