Java Reference
In-Depth Information
Q :
What makes a static nested class different from a non- static one?
A : A static nested class is one that has the static modifier applied. Because it is static , it
can access only other static members of the enclosing class directly. It must access
other members of its outer class through an object reference.
Beginning with JDK 5, this need was addressed by the inclusion of a feature that sim-
plified the creation of methods that require a variable number of arguments. This feature
is called varargs , which is short for variable-length arguments. A method that takes a vari-
able number of arguments is called a variable-arity method , or simply a varargs method .
The parameter list for a varargs method is not fixed, but rather variable in length. Thus, a
varargs method can take a variable number of arguments.
Varargs Basics
A variable-length argument is specified by three periods (…). For example, here is how to
write a method called vaTest( ) that takes a variable number of arguments:
Notice that v is declared as shown here:
This syntax tells the compiler that vaTest( ) can be called with zero or more arguments.
Furthermore, it causes v to be implicitly declared as an array of type int[ ] . Thus, inside
vaTest( ) , v is accessed using the normal array syntax.
Here is a complete program that demonstrates vaTest( ) :
Search WWH ::




Custom Search