This chapter reviews method parameters and local variables, as well as method overloading and method signature.
Method overloading means two or more methods have the same name but have different parameter lists: either a different number of parameters or different types of parameters. When a method is called, the corresponding method is invoked by matching the arguments in the call to the parameter lists of the methods. The name together with the number and types of a method's parameter list is called the signature of a method. The return type itself is not part of the signature of a method.
19. Overloaded println()
Answer:
Yes. The names of the formal parameters do not have to be unique.
Overloaded println()
println()
We have already been using overloading. The println()
method (for example) has several overloaded versions:
- println( )
- println( boolean x )
- println( char x )
- println( double x )
- println( int x )
- println( String x )
- ... others
Which version of println()
gets called depends on the argument.
Question 19:
Which version of println()
is called in the following:
System.out.println( "The result is: " + 34 );