Question: Consider the following code snippet: public static void main ( String [ ] args ) { ArrayList names = new ArrayList ( ) ; names.add

Consider the following code snippet:
public static void main(String[] args)
{
ArrayList names = new ArrayList();
names.add("John");
names.add("Jerry");
names.add("Janet");
ArrayList names2= reverse(names);
}
public static ArrayList reverse(ArrayList names)
{
ArrayList result = new ArrayList();
for (int i = names.size()-1; i >=0; i--)
{
result.add(names.get(i));
}
return result;
}
Which statement is true after the main method is executed?
Question 8 options:
names contains "Janet", "Jerry", "John" in this order.
names contains "John", "Jerry", "Janet" in this order.
reverse method has a bound error.
Compilation error due to the return statement in reverse method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!