Submitted by c-admin on Wed, 05/29/2019 - 05:57
Which of the following are valid code fragments:
Select 2 options
A. new Object[]{ "aaa", new Object(), new ArrayList(), 10};
B. new Object[]{ "aaa", new Object(), new ArrayList(), {} };
C. new Object[]{ "aaa", new Object(), new ArrayList(), new String[] {""} };
D. new Object[1]{ new Object() };
Submitted by c-admin on Wed, 05/29/2019 - 05:54
Given the complete contents of TestClass.java file:
package x;
public class TestClass {
ArrayList<String> al;
public void init(){
al = new ArrayList<>();
al.add("Name 1");
al.add("Name 2");
}
public static void main(String[] args) throws Exception {
TestClass tc = new TestClass();
tc.init();
System.out.println("Size = "+tc.al.size());
}
}
Which import statement should be added to make it compile?
Select 1 option
A. import java.lang.*;
B. import java.lang.ArrayList;
C. import java.util.ArrayList;
D. import java. Collections. ArrayList;
E. No import is necessary.
Submitted by c-admin on Wed, 05/29/2019 - 05:51
What will the following code print when compiled and run?
import java.util.*;
public class TestClass {
public static void main(String[] args) throws Exception {
ArrayList<Integer> al = new ArrayList<>(); //1
al.add(111); //2
System.out.println(al.get(al.size())); //3
}
}
Select 1 option
A. It will not compile.
B. It will throw an exception at run time because of line //1
C. It will throw an exception at run time because of line //2
D. It will throw an exception at run time because of line //3
E. null.
Submitted by c-admin on Wed, 05/29/2019 - 05:47
Given:
import java.util.*;
public class TestClass {
public static void main(String[] args) throws Exception {
ArrayList<Double> al = new ArrayList<>();
//INSERT CODE HERE
}
}
What can be inserted in the above code so that it can compile without any error?
Select 3 options
A. al.add (111);
B. System.out.println (al.indexOf (1.0));
C. System.out.println (al.contains ("string"));
D. Double d = al.get (al.length);
E. al.notifyAll();
Submitted by c-admin on Wed, 05/29/2019 - 05:43
Identify the correct statements about ArrayList?
Select 3 options
A. ArrayList extends java.util.AbstractList.
B. It allows you to access its elements in random order.
C. You must specify the class of objects you want to store in ArrayList when you
declare a variable of type ArrayList.
D. ArrayList does not implement RandomAccess.
E. You can sort its elements using Collections.sort() method.
Pages