πŸ“Š JAVA
Q. What will be the output of the following Java program?
public class BoxDemo
{
public static <U> void addBox(U u,
java.util.List<Box<U>> boxes)
{
Box<U> box = new Box<>();
box.set(u);
boxes.add(box);
}
public static <U> void outputBoxes(java.util.List<Box<U>> boxes)
{
int counter = 0;
for (Box<U> box: boxes)
{
U boxContents = box.get();
System.out.println("Box #" + counter + " contains [" + boxContents.toString() + "]");
counter++;
}
}
public static void main(String[] args)
{
java.util.ArrayList<Box<Integer>> listOfIntegerBoxes = new java.util.ArrayList<>();
BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes);
BoxDemo.outputBoxes(listOfIntegerBoxes);
}
}
  • (A) 10
  • (B) Box #0 [10]
  • (C) Box contains [10]
  • (D) Box #0 contains [10]
πŸ’¬ Discuss
βœ… Correct Answer: (D) Box #0 contains [10]

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
89
Total Visits
πŸ“½οΈ
12 mo ago
Published
πŸŽ–οΈ
Ram Avtar Sharma
Publisher
πŸ“ˆ
94%
Success Rate