Java Reference
In-Depth Information
Although the parameter lists of
vaTest( )
differ, there is no way for the compiler to resolve
the following call:
vaTest(1)
Does this translate into a call to
vaTest(int …)
, with one varargs argument, or into a call to
vaTest(int, int …)
with no varargs arguments? There is no way for the compiler to answer
this question. Thus, the situation is ambiguous.
Because of ambiguity errors like those just shown, sometimes you will need to forego
overloading and simply use two different method names. Also, in some cases, ambiguity
errors expose a conceptual flaw in your code, which you can remedy by more carefully
crafting a solution.
Chapter 6 Self Test
is the following fragment correct?
likened to a stack of plates. The first plate put on the table is the last plate used.
Create a stack class called
Stack
that can hold characters. Call the methods that ac-
cess the stack
push( )
and
pop( )
. Allow the user to specify the size of the stack when