Syntax Quiz 2, Step 6
Assignment:
Write a variable declaration for a parameter variable named
theParameter
of a type suitable to hold a character string.
My solution:
String theParameter
Common mistakes:
- Omitting the type.
- Every variable (whether instance, parameter, or local) must be declared
with a type before it.
- Mis-spelling the type.
- The built-in type name
String
must be capitalized;
Java has never heard of a type named string
.
- Including a semicolon at the end.
- Instance and local variables are declared in declaration
statements, which end in semicolons. However, parameter
variables are declared inside a method header, and do
not end in semicolons.
Stephen Bloch / sbloch@adelphi.edu