This is how you create an object from a class in Java.
What is using the new keyword?
This keyword is used to create a blueprint for an object.
What is class?
This type of loop is best suited for traversing an array when the size is known.
What is a for loop?
This Java keyword is used to execute code only when a condition evaluates to true.
What is if?
This is the syntax to declare a 2D array in Java with 3 rows and 4 columns.
What is int[][] arr = new int[3][4];?
This loop repeatedly executes a block of code as long as its condition remains true.
What is a while loop?
In Java, this special method is used to initialize an object when it is created.
This is the syntax to declare and initialize an array of integers in Java with values 1, 2, and 3.
What is int[] arr = {1, 2, 3};? (answer must include {curly brackets})
This operator combines two conditions and evaluates to true only if both are true.
What is &&?
The row and column indices of the top-left corner of a 2D array.
What are [0][0]?
This feature of object-oriented programming allows you to reuse code by deriving new classes from existing ones.
What is inheritance?
This type of method belongs to the class rather than any object instance.
What is a static method?
This is the syntax for an enhanced for loop to iterate over an integer array arr.
What is for (int num : arr)?
The keyword used to specify an alternative block of code if the condition in an if statement is false.
What is else?
This is the output of arr[1][2] for a 2D array arr = {{1,2,3}, {4,5,6}, {7,8,9}}.
What is 6?
This principle of OOP involves breaking down a complex problem or system into smaller, more manageable parts.
What is decomposition?
These are the components of a class that define the behavior and characteristics of its objects.
What are fields and methods?
Write a method named findSum that takes an array of integers as input and returns the sum of all the elements in the array.
public static int findSum(int[] arr) {
int sum = 0;
for (int num : arr) {
sum += num;
}
return sum;
}
This logical law states that the negation of a conjunction is equivalent to the disjunction of the negations, and vice versa.
What is DeMorgan's Law?
This loop structure is commonly used to iterate through all elements of a 2D array.
What are nested for loops?
These three programming constructs allow you to write algorithms in Java effectively.
What are sequencing, selection, and iteration?
This keyword is used in a subclass to call a constructor or method from its superclass, ensuring proper initialization or reuse of inherited behavior.
What is super?
Write a method named reverseArray that takes an array of integers as input and returns a new array containing the elements in reverse order.
public static int[] reverseArray(int[] arr) {
int[] reversed = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
reversed[i] = arr[arr.length - 1 - i];
}
return reversed;
}
This is the value of the expression (true || false) && false
What is false?
The term for when you traverse a 2D array diagonally from the top-left to the bottom-right.
What is diagonal traversal?