1

What will be the output of the following Java program? public class BoxDemo { public static void addBox(U u, java.util.List> boxes) { Box box = new Box<>(); box.set(u); boxes.add(box); } public static void outputBoxes(java.util.List> boxes) { int counter = 0; for (Box box: boxes) { U boxContents = box.get(); System.out.println("Box #" + counter + " contains [" + boxContents.toString() + "]"); counter++; } } public static void main(String[] args) { java.util.ArrayList> listOfIntegerBoxes = new java.util.ArrayList<>(); BoxDemo.addBox(Integer.valueOf(10), listOfIntegerBoxes); BoxDemo.outputBoxes(listOfIntegerBoxes); } }

Correct Answer: Box #0 contains [10]

Make the most of this question

This page focuses on one JAVA MCQs question from Programming. After checking the answer, return to the topic list to practice more or run a timed set.

JAVA MCQs MCQ: What will be the output of the following Java program? public class BoxDemo { public static void addBox(U u, java.util.List > boxes) { Box box = new Box<>(); box.set(u); boxes.add(box); } public static void outputBoxes(java.util.List > boxes) { int counter = 0; for (Box box: boxes) { U boxContents = box.get(); System.out.println("Box #" + counter + " contains [" + boxContents.toString() + "]"); counter++; } } public static void main(String[] args) { java.util.ArrayList > listOfIntegerBoxes = new java.util.ArrayList<>(); BoxDemo. addBox(Integer.valueOf(10), listOfIntegerBoxes); BoxDemo.outputBoxes(listOfIntegerBoxes); } } | Extra Education