Advanced
Compilers & Programming Language Theory
Q83 / 100
What is the difference between nominal and structural typing?
Correct! Well done.
Incorrect.
The correct answer is B) Nominal typing: types are compatible only if they have the same name/declaration. Structural typing: types are compatible if they have the same structure (duck typing formalized)
B
Correct Answer
Nominal typing: types are compatible only if they have the same name/declaration. Structural typing: types are compatible if they have the same structure (duck typing formalized)
Explanation
Nominal (Java, C#): Dog and Cat are different types even if they have the same fields. Structural (Go interfaces, TypeScript): any type with matching methods satisfies the interface. Structural is more flexible; nominal catches more accidental coincidences.
Progress
83/100