Hats Puzzle is based on logical thinking.
The answer:
If person B and C's hat are the same color, person A will know the color of his hat because there are two white hats and two black hats, meaning that if B and X's hat are white, person A will answer that his hat is the color Black and if B and C's hat are black, A will answer that his hat is white
Since (A) did not answer, person (B) knew that (A) saw two hats of different colors, one white and the other black, and since person (B) sees the hat that D is wearing, of course, he will answer that his hat is white.