Class Basics
Object Concepts
Arrays
ArrayLists
Code Tracing
100

What keyword is used to create a new class in Java?

What is class?

100

This keyword is used to instantiate an object.

What is new?

100

This is the index of the first element in a Java array.

What is 0?

100

This Java package must be imported to use ArrayList.

What is import java.util.ArrayList;?

100

int[] a = {1, 2, 3}; System.out.println(a[1]);

What is 2?

200

This method is automatically called when an object is created.

What is a constructor?

200

This is how you call the method printDetails on an object named book1.

What is book1.printDetails();?

200

This is how you declare an array of 10 integers.

What is int[] arr = new int[10];?

200

This method adds an element to an ArrayList.

What is add()?

200

ArrayList<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.remove(0); System.out.println(list);

What is [B]?

300

This type of variable belongs to the object, while the other is only visible inside methods.

What is an instance variable (vs. local variable)?

300

This keyword is used inside a class to refer to the current object.

What is this?

300

This happens when you try to access an index that is out of bounds.

What is ArrayIndexOutOfBoundsException?

300

This is the main difference between an array and an ArrayList.

What is: ArrayLists can change size dynamically, arrays have fixed size?

300

Student s = new Student("John", 90); s.setGrade(95); System.out.println(s.getGrade());

What is 95?

400

This is true about the number of constructors a class can have.

What is "A class can have multiple constructors"?

400

This keyword creates a new object in memory and calls the constructor.

What is new?

400

This property or method gives you the number of elements in an array named nums.

What is nums.length?

400

This method removes an element at a specific index in an ArrayList.

What is remove(index)?

400

int[] nums = {2, 4, 6}; int sum = 0; for (int n : nums) { sum += n; } System.out.println(sum);

What is 12?

500

This code defines a class Book with two fields, title and author, and a constructor to initialize them.

What is:
public class Book {

String title, author;

public Book(String t, String a) {

 title = t;

 author = a;

  }}

500

This is what happens in memory when Car myCar = new Car(); is executed.

What is: A new Car object is created in memory, and myCar stores its reference?

500

This loop sums all the values in an int[] called scores.

What is:
int sum = 0;

for (int s : scores) {

 sum += s; 

}

500

This code snippet creates an ArrayList of Strings and adds three names.

What is:
ArrayList<String> names = new ArrayList<>();<names.add("Alice");

names.add("Bob");

names.add("Carol");

500

ArrayList<Integer> nums = new ArrayList<>(); nums.add(1); nums.add(2); nums.set(1, 5); System.out.println(nums);

What is [1, 5]?

M
e
n
u