Sample Booklet
Sample Booklet
Grade 11
5. Which of the following is the correct syntax for a method named display in Java?
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<int> list = new ArrayList<>();
list.add(10);
list.add(20);
System.out.println(list.get(0));
}
}
4. Find the error in the following code snippet and explain why it occurs:
import java.util.ArrayList;
import java.util.LinkedList;
// Constructor here
}
2. To create an array of integers in Java with 5 elements, we can use the following declaration:
3. To add an element at the beginning of an ArrayList in Java, you can use the _________ method.