So, I have this true/false question in my computer science class (we’re using Java):
A declaration of a variable name declares the type of value to be
stored there.
(the word “type” was bold in the question)
Now, I know that when you declare a variable you must specify the type in Java because it is statically typed:
int x;
In that code, a variable with the name of x is declared, and we know it is of type int.
However the question mentioned the term “variable name”. Technically, the name/identifier of the variable is not responsible for declaring the variable’s type. The name doesn’t even need to allude to the variable’s type if the programmer chooses.
I was wondering what the right choice would be here. Would it be true or false? To me it seems rather ambiguous… what should I do?
The question is specific: “A declaration of a variable name declares…” (emphasis mine)
If it said “A variable name declares…” you may be correct in assuming this to be a trick question. However, since the question specifically targets the declaration itself, the correct answer is true.