-
Book Overview & Buying
-
Table Of Contents
OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808
By :
As you saw in the previous chapter, a method may use a vararg parameter (variable argument) as if it is an array. It is a little different than an array, though. A vararg parameter must be the last element in a method's parameter list. This implies you are only allowed to have one vararg parameter per method.
Can you identify why each of these does or doesn't compile? (Yes, there is a lot of practice in this chapter. You have to be really good at identifying valid and invalid methods for the exam.)
public void walk1(int… nums) { }
public void walk2(int start, int… nums) { }
public void walk3(int… nums, int start) { } // DOES NOT COMPILE
public void walk4(int… start, int… nums) { } // DOES NOT COMPILE
walk1() is a valid method declaration with one vararg parameter. walk2() is a valid method declaration with one int parameter and one vararg parameter. walk3() and walk4() do not compile because they have a vararg parameter...
Change the font size
Change margin width
Change background colour