GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 24

Static types and runtime subtypes

Engineering Mathematics & Other Topics · Other Computing Topics · Full GATE CSE 2003 paper

GATE 2003, Q24 1 mark · MCQ
Not in GATE 2027 syllabusReport issue

Other Computing Topics

Question 24, GATE 2003: Which typing statement is false? A. In statically typed languages each program variable has a fixed type; B. In untyped languages values do not have types; C. In dynamically typed languages variables have no types; D. In all statically typed languages each variable is associated with values of only a single type during execution.
Tap to enlarge
Your answer
Answer & solution

Answer: D under the standard polymorphic-language distinction (no official key was published)

1. Static type and runtime class are different concepts. A variable declared as a superclass reference retains that declared type while holding references to multiple subclasses. This gives a counterexample to D without implying that the compiler changes the declared type of the variable.

2. A variable in a statically typed language can have one declared static type while referring at different times to values of different compatible runtime subtypes. For example an Animal reference may refer to Dog and Cat objects. Thus D’s claim that values must have only a single runtime type in all statically typed languages is false. The other statements use the conventional distinction between declared variable types, dynamically typed values and untyped formalisms; that terminology is not uniform across every language theory.

Original paper, page 3