adplus-dvertising
frame-decoration

Question

What is the output of this 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].

Posted under Java Programming

Answer: (d).Box #0 contains [10].

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?

Similar Questions

Discover Related MCQs

Q. Which of these is wildcard symbol?

Q. What is use of wildcards?

Q. Which of these keywords is used to upper bound a wildcard?

Q. Which of these is an correct way making a list that is upper bounded by class Number?

Q. Which of the following keywords are used for lower bounding a wild card?

Q. Which of the following is not an Enterprise Beans type?

Q. Which of the following is not true about Java beans?

Q. Which file separator should be used by MANIFEST file?

Q. Which of the following is correct error when loading JAR file with duplicate name?

Q. Java Beans are extremely secured?

Q. Which of the following is not a feature of Beans?

Q. What is the attribute of java bean to specify scope of bean to have single instance per Spring IOC?

Q. Which attribute is used to specify initialization method?

Q. Which attribute is used to specify destroy method?

Q. How to specify autowiring by name?

Q. Which of the following contains both date and time?

Q. Which of the following is advantage of using JDBC connection pool?

Q. Which of the following is advantage of using PreparedStatement in Java?

Q. Which one of the following contains date information?

Q. What does setAutoCommit(false) do?