This keyword refers to the current object in a class.
What is `this`?
This is the output of this loop:
for (int i = 1; i <= 3; i++)
System.out.print(i);
What is 123?
This code creates an array of 10 doubles.
What is double[] arr = new double[10];?
This keyword is used when a class inherits from another.
What is extends?
This method returns true if the input integer is odd.
What is return n % 2 != 0;?
This principle is followed when instance variables are declared private.
What is encapsulation?
This type of loop is preferred when the number of iterations is not known in advance.
What is a while loop?
This method removes an element from an ArrayList by index.
What is .remove(index)?
This keyword allows a subclass constructor to call a parent constructor.
What is super()?
This is the result of
String s = "ab";
s += "cd";
System.out.print(s);
What is abcd?
This is the value of a static counter incremented in a constructor after 3 objects are created.
What is 3?
This type of loop never terminates because the condition always evaluates to true.
What is an infinite loop?
This loop structure is commonly used to traverse all elements in an array.
What is a for-each loop?
This type of method cannot be overridden because it is not inherited.
What is a private method?
This is the output of the following loop:
for (int i = 1; i <= 3; i++) {
System.out.print(i);
}
What is 123?
These are the two main differences between static and instance variables.
What are shared across all instances vs. belonging to individual objects?
This is the output of this code:
int x = 5;
while (x > 0)
{
x--;
if (x == 2)
break;
}
System.out.print(x);
What is 2?
This is the output of:
int[] a = {1,2};
int[] b = a;
b[0] = 99;
System.out.println(a[0]);
What is 99?
This method runs when the following code executes: Animal a = new Dog(); a.makeSound();
What is the Dog version of makeSound()?
This is the output of the following code:
String word = "java";
System.out.println(word.substring(1, 3));
What is av?
This issue occurs when a constructor parameter has the same name as an instance variable but doesn’t use `this`.
What is variable shadowing?
This method returns the first multiple of 2 in an int[], or -1 if not found.
What is
for(int n : arr)
if(n % 15 == 0)
return n;
return -1;
?
This is the result of running the method below when passed the array {3, 6, 9}:
public static void reversePrint(int[] arr) {
for (int i = arr.length - 1; i >= 0; i--) {
System.out.print(arr[i]);
}
}
What is 963?
This concept allows objects of different classes to be treated as objects of a common superclass.
What is polymorphism?
This is the output of the following code:
int[] nums = {3, 1, 4};
int sum = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] % 2 != 0) {
sum += nums[i];
}
}
System.out.println(sum);
What is 4?