Syntax Quiz 2, Step 8
Assignment:
Write a variable declaration for a local variable named
localVar
of a type suitable to hold a floating-point number.
My solution:
double localVar;
Common mistakes:
- Omitting or mis-placing the type name.
- Every variable, whether instance, parameter, or local, must be
declared with a specific type, using the syntax
type-name var-name
- Omitting the semicolon.
- Local variables are declared in declaration statements,
which like all other statements must end in a semicolon.
- Putting a
private
or
public
in front.
- The modifiers "private" and "public" don't make sense for local
variables (we'll see why later in the semester).
Stephen Bloch / sbloch@adelphi.edu