A child born in wedlock takes the surname of the parents; provided, however that if the parents divorce before the child is born, the child takes the surname used by the parents at the time of divorce.
嫡出である子は、父母の氏を称する。ただし、子の出生前に父母が離婚したときは、離婚の際における父母の氏を称する。
A child not born in wedlock takes the surname of the mother.
嫡出でない子は、母の氏を称する。
Read this with the articles around it