Questions: Type Systems and Type Safety

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer argues that Python is 'type-unsafe' because it doesn't check types before the program runs. A classmate disagrees. Who is correct, and why?

AThe first programmer is right — without compile-time checking, there is no meaningful type safety
BThe classmate is right — Python performs type checking at runtime, which still prevents invalid operations and provides genuine type safety
CBoth are partially right — Python is type-safe only for built-in types, not user-defined ones
DThe question is moot because Python's type system is functionally identical to Java's, just triggered at a different moment
Question 2 Multiple Choice

In a statically typed language, a function is declared to return an integer. You store its result in a variable and then try to call .toUpperCase() on it (a string method). What happens?

AThe program executes the call and produces undefined or garbage output
BThe runtime silently converts the integer to a string so the method can proceed
CThe compiler refuses to build the program, because the type system knows the variable holds an integer and string methods are not valid on integers
DThe function detects how its return value will be used and adjusts its return type accordingly
Question 3 True / False

Type safety is a property unique to statically typed languages, since dynamically typed languages mainly check types at runtime where errors can still cause crashes.

TTrue
FFalse
Question 4 True / False

In a statically typed language, knowing the declared type of a variable tells you what operations you can safely perform on it before the program ever runs.

TTrue
FFalse
Question 5 Short Answer

What does a type system fundamentally do, and why does it matter whether type checking happens at compile time or at runtime?

Think about your answer, then reveal below.