![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson | Search |
Local variables and member variables can be initialized with an assignment statement when they're declared. The data type of both of the assignment operator's operands must match. TheMaxVariables
program provides initial values for all of its local variables when they are declared. The variable declarations from that program is shown below with the initialization code in red:
Method parameters and exception-handler parameters cannot be initialized in this way. The value for a parameter is set by the caller.// integers byte largestByte = Byte.MAX_VALUE; short largestShort = Short.MAX_VALUE; int largestInteger = Integer.MAX_VALUE; long largestLong = Long.MAX_VALUE; // real numbers float largestFloat = Float.MAX_VALUE; double largestDouble = Double.MAX_VALUE; // other primitive types char aChar = 'S'; boolean aBoolean = true;
![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson | Search |