ArrayList Class

1

What is the output of this program?

What is the output of this program?

    class Output {
        public static void main(String args[])
        {
            int a1[] = new int[10];
            int a2[] = {1, 2, 3, 4, 5};
            System.out.println(a1.length + " " + a2.length);
        } 
    }
A. 10 5
B. 5 10
C. 0 10
D. 0 5

2

What is the output of this program?

  
    class Output {
        public static void main(String args[]) {
            ArrayList obj = new ArrayList();
            obj.add("A");
            obj.add("D");
            obj.ensureCapacity(3);
            obj.trimToSize();
            System.out.println(obj.size());
         }      
    }
A. 1
B. 2
C. 3
D. 4

3

What is the output of this program?

    class Output {
        public static void main(String args[])
        {
            int arr[] = {1, 2, 3, 4, 5};
            for ( int i = 0; i < arr.length - 2; ++i)
                System.out.println(arr[i] + " ");
        } 
    }
A. 1 2
B. 1 2 3
C. 1 2 3 4
D. 1 2 3 4 5

4

What is the output of this program?

  
    import java.util.*; 
    class Output {
        public static void main(String args[]) { 
            TreeSet t = new TreeSet();
            t.add("3");
            t.add("9");
            t.add("1");
            t.add("4");
            t.add("8"); 
            System.out.println(t);
        }
    }
A. [1, 3, 5, 8, 9]
B. [3, 4, 1, 8, 9]
C. [9, 8, 4, 3, 1]
D. [1, 3, 4, 8, 9]

5

What is the output of this program?

    class Output {
         public static void main(String args[]) {
            double x = 2.0;  
            double y = 3.0;
            double z = Math.pow( x, y );
            System.out.print(z);
        }
    }
A. 2.0
B. 4.0
C. 8.0
D. 9.0