217k views
2 votes
What method signature can be used to replace YYYYYYYY in the following code, such that the call to add(stack1, stack2) will result in successful compilation and execution?

User Jake H
by
7.8k points

1 Answer

3 votes

Answer:

? super T method is used to replace YYYYYYYY in the following code, such that the call to add(stack1, stack2)

public class WildCardDemo3 {

public static void main(String[] args) {

GenericStack<String> stack1 = new GenericStack<>();

GenericStack<Object> stack2 = new GenericStack<>();

stack2.push("Java");

stack2.push(2);

stack1.push("Sun");

add(stack1, stack2);

WildCardDemo2.print(stack2);

}

public static <T> void add(GenericStack<T> stack1,

GenericStack<YYYYYYYY> stack2) {

while (!stack1.isEmpty())

stack2.push(stack1.pop());

}

}

Step-by-step explanation:

super can be used to refer immediate parent class instance variable. super can be used to invoke immediate parent class method. super() can be used to invoke immediate parent class constructor.

User Mateusz Szlosek
by
7.5k points