Introduction to Computer Science
Grade 11
Sample Question Booklet
Course Code: ICS3U Teacher: Namarta Vij
Student Name: ________________ Date: 1-28-2025
Section 1: Multiple-Choice Questions (5 Marks)
1. Which of the following is true about arrays in Java?
a) Arrays are of fixed size
b) Arrays can grow in size dynamically
c) Arrays are always multidimensional
d) None of the above
2. What is a constructor in a class?
a) A method to initialize objects
b) A static block
c) A method that returns void
d) None of the above
3. Which of these is a characteristic of objects?
a) An object must have at least one method
b) Objects are instances of classes
c) Objects are methods of a class
d) None of the above
4. Which method is used to find the size of an ArrayList?
a) size()
b) length()
c) count()
d) capacity()
5. Which of the following is the correct syntax for a method named display in Java?
a) public display void() { [Link]("Hello"); }
b) void display() { [Link]("Hello"); }
c) public void display() { [Link]("Hello"); }
d) display public void() { [Link]("Hello"); }
Section 2: Find the Error (4 Marks)
1. Find the error in the following ArrayList code:
import [Link];
public class Test {
public static void main(String[] args) {
ArrayList<int> list = new ArrayList<>();
[Link](10);
[Link](20);
[Link]([Link](0));
}
}
2. Find the error below:
public class LoopTest {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
for (i = 0; i < [Link]; i++) {
[Link](arr[i]);
}
}
}
3. Find the Error Question on while (true) Loop
public class WhileLoopTest {
public static void main(String[] args) {
while (true)
[Link]("This is an infinite loop.");
[Link]("This will never be printed.");
}
}
4. Find the error in the following code snippet and explain why it occurs:
public class ForLoopTest {
public static void main(String[] args) {
for (int i = 0; i <= 5; i++) {
[Link](i);
}
[Link](i); // Error occurs here
}
}
Section 3: What is the Output? (4 Marks)
1. Predict the output of this code:
public class Test {
String name;
public Test(String name) {
[Link] = name;
}
public static void main(String[] args) {
Test obj = new Test("John");
[Link]([Link]);
}
}
2. What will be the output of the following code snippet?
public class ArrayTest {
public static void main(String[] args) {
int[] arr = {10, 20, 30, 40};
arr[1] = 50;
[Link](arr[1]);
}
}
3. What will be the output of the following code snippet?
import [Link];
public class ArrayListTest {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
[Link](10);
[Link](20);
[Link](30);
[Link](1, 15);
[Link](list);
}
}
4. What will be the output of the following code snippet?
import [Link];
public class LinkedListTest {
public static void main(String[] args) {
LinkedList<Integer> list = new LinkedList<>();
[Link](10);
[Link](20);
[Link](5);
[Link](25);
[Link](list);
}
}
Section 4: Fill in the Blanks (2 Marks)
1. Complete the constructor in the following class:
public class Employee {
String name;
int id;
// Constructor here
}
2. To create an array of integers in Java with 5 elements, we can use the following declaration:
int[] arr = new ________(5);
3. To add an element at the beginning of an ArrayList in Java, you can use the _________ method.
4. To create an object of a class Person in Java, we would write:
Section 5: Theory Questions (5 Marks)
1. Explain the difference between an array and an ArrayList.
2. What is the difference between a class, an object, and a method?
Section 6: Programming Question (5 Marks)
1. Write a Java program to find the factorial of a number using a loop.
Sample Input: 5
Sample Output: 120