The document discusses Java concepts related to generics and collections. It asks 4 multiple choice questions:
1. Which statements about adding elements to an ArrayList are correct.
2. Which wildcard can replace YYYYYYYY in a generic method adding elements from one stack to another.
3. Which statement about using the Comparable interface is correct.
4. Which wildcard can replace YYYYYYYY in a generic method with a bounded type parameter.
ex777777 I Suppose ArrayListlist - new ArrayList()- Which of the follo.docx
1. ex777777
I Suppose ArrayListlist = new ArrayList(). Which of the following statements are correct? A,
double d = list.get(1); // Automatically converted to double B. list.add(3.0); // 3.0 is
automatically converted to new Double(3.0) C. Double doubleObject - list.get(0); // No casting is
needed D. list.add(5.5); // 5.5 is automatically converted to new Double(5.5) 2 Which of the
following can be used to replace YYYYYYYY in the following code? public class
WildCardDemo3{ public static void main(String[] args) { GenericStack stack! = new
GenericStackString>(); GenericStack stack2 = new GenericStack(); stack2.push("Java");
stack2.push(2); stackl push("Sun"); add(stackl, stack2); WildCardDemo2.print(stack2); public
static T> void add(GenericStackT> stack 1, GenericStack stack2){ while (!stackl.isEmpty))
stack2.push(stack1.pop)); A. ? extends T B. ? extends Object C. ? super T D. ? super Object 3
Which of the following statements is correct? A. ComparableString> c-"abc"; B.
ComparableString c = new String("abc"); C. Comparable c = new Date(); D.
ComparableString> c new Date(); 4 Which of the following can be used to replace
YYYYYYYY in the following code? public class WildCardDemo3 public static void
main(String[] args) f
Solution
Ans. Statemnts A,B,C,D are correct
Ans. Option C.
Ans. Option A & B
Ans. Option A & C
Ans. Option D
Ans.Option A
Ans. Option D
Ans.Option A