Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Local variables and member variables can be initialized with an assignment statement when they're declared. The data type of the variable must match the data type of the value assigned to it. TheMaxVariablesDemo
program provides initial values for all its local variables when they are declared. The local variable declarations from that program follow, with the initialization code set in red: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
Feedback Form |
Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.