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("[" + boxContents.toString() + "]");
                counter++;
            }
        }
        public static void main(String[] args)
        {
            java.util.ArrayList<Box<Integer>> listOfIntegerBoxes = new java.util.ArrayList<>();
            BoxDemo.<Integer>addBox(Integer.valueOf(0), listOfIntegerBoxes);
            BoxDemo.outputBoxes(listOfIntegerBoxes);
        }
    }

a.

0

b.

1

c.

[1].

d.

[0].

Posted under Java Programming

Answer: (d).[0].

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. A java interface can contain _______.

Q. Which of the following is a correct interface?

Q. Which of the following classes directly implement Set interface?

Q. Which is the correct way to inherit and implement the interface?

Q. Which of the following is true about methods in an interface in java?

Q. Can "abstract" keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization Block.

Q. Package in Java is a mechanism to encapsulate a ______________.

Q. Package names and directory structure are closely related.

Q. An _______________ statement can be used to access the classes and interface of a different package from the current package.

Q. Which of the following packages is used to includes classes to create user interface like Button and Checkbox?

Q. Which of the following packages is used to includes utility classes like Calendar, Collection, Date?

Q. Which of the following is the correct way of importing an entire package "pkg"?

Q. Which of the following is false statement about package in java?

Q. Packages that are inside another package are the _________

Q. An interface in Java is like a 100% ____.

Q. A Java Interface is not considered a class. State TRUE or FALSE.

Q. Choose the correct syntax below for defining an Interface in Java.

Q. Choose a correct statement about Java Interfaces?

Q. A Java Class inheritsConstants and Methods of an Interface using ____ keyword.

Q. All Interface variables are ___ by default in Java.