1/56
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What are the benefits of using a method?
Reuse code, reduce complexity, easy to maintain.
What keyword can be used as a return type for a method that does not return any value?
void
What does the signature of a method consist of?
Method name and parameter list.

What must all Java applications have?
public static void main(String[] args)
Where do arguments to methods always appear?
Within parentheses.
What area of memory stores parameters and local variables each time a method is invoked?
A stack.
What is the return type of a main method?
void
What is the method header for returning a sales commission given the sales amount and commission rate?
public static double getCommission(double salesAmount, double commissionRate)
What causes a compile error in the provided program?
public class Test {
public static void main(String[] args) {
System.out.println(m(2));
}
public static int m(int num) {
return num;
}
public static void m(int num) {
System.out.println(num);
}
}
The program has a compile error because the two methods m have the same signature.
What is a variable defined inside a method called?
A local variable.
What happens to variable k after the block executes?
{
int k = 2; nPrint("A message", k);
}
System.out.println(k);
k is not defined outside the block. So, the program has a compile error.
What is method overloading?
Two methods with the same name, defined in the same class, is called method overloading.
What is the size of an array once created?
The size is fixed.
Which declarations are correct for an array of int values?
int[] a; and int a[];
True or False: Every element in an array has the same type.
True
True or False: The array size is fixed after an array reference variable is declared.
False.
What is the expression to create an array of the int type with size 40?
new int[40]
Which array declarations are incorrect?
int[] a = new int(2);, int a = new int[2];, int a() = new int[2];
What is the highest index in an array double[] list = new double[5]?
4.
What is list.length for int[] list = new int[6]?
6.
How many elements are in array double[] list = new double[5]?
5.
What does the program output when x[0] is printed?
public class Test {
public static void main(String[] args) {
int[] x = new int[3];
System.out.println("x[0] is " + x[0]);
} }
The program runs fine and displays x[0] is 0.
What is the array index type and its lowest index?
The array index type is int and its lowest index is 0.
Which statements are valid for array declarations?
double d[] = new double[30]; and int[] i = {3, 4, 3, 2};
What is list[1] for double[] list = {3.4, 2.0, 3.5, 5.5}?
2.0.
What is t.length for int[] t = {1, 2, 3, 4}?
4.

What is the output of this code?
1 1 1 1 1 1.

What is the output of the code that finds the index of the maximum value in myList?
1.
What happens when list2 is assigned to list1?
list2 points to the same array as list1.
What method copies the sourceArray to the targetArray?
System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
True or False: When an array is passed to a method, a new array is created.
False.
What is the output of the program that prints the second element of the array x initialized with {1, 2, 3}?
Value is 2.0
When you pass an array to a method, what does the method receive?
The reference of the array
Where does the JVM store arrays for dynamic memory allocation?
Heap
Which of the following array initializations is correct?
String[] list = new String[]{"red", "yellow", "green"}; and String[] list = {"red", "yellow", "green"};
What is the content of the list after the first iteration of selectionSort on {3.1, 3.1, 2.5, 6.4, 2.1}?
2.1, 3.1, 2.5, 6.4, 3.1
Which of the following is a correct header for the main method?
public static void main(String[] args) and public static void main(String args[]) and public static void main(String[] x) and public static void main(String x[])

Which statement about multidimensional arrays is correct?
char[][] charArray = {{'a', 'b'}, {'c', 'd'}};
What is the indexed variable for the element at the first row and first column in array a?
a[0][0]
True or False: When creating an int[][] matrix with new int[5][5], the element values are automatically initialized to 0.
True
What is the output of the code that prints the second column of a 2D matrix?
2 5 9 13
What is the output of the code that prints data[1][0][0] from a 3D array?
public class Test {
public static void main(String[] args) {
int[][][] data = {{{1, 2}, {3, 4}},
{{5, 6}, {7, 8}}};
System.out.print(data[1][0][0]);
}
}
5

What’s the output of the following code?
4

How do you declare a three-dimensional array in Java?
int[][][] m = new int[4][6][5];
What does System.out.println(array[0][0][0]) print for the given 3D array?
1
Can the rows in a two-dimensional array have different lengths?
Yes, they are ragged arrays.
What are the lengths of the rows in the array x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}?
2, 3, and 4
What is an Object in Object-Oriented Programming?
An instance of a class.
What is a Constructor in Object-Oriented Programming?
A special kind of method that is invoked to create an object.
What is the State of an object in Object-Oriented Programming?
The properties or attributes represented by data fields.
What is the Behavior of an object in Object-Oriented Programming?
Defined by methods.
What is a Class in Object-Oriented Programming?
A template or blueprint that defines an object's data fields and methods.
What is the default value for a boolean, numeric, and object type in Java?
false, 0, null
What is an instance method?
A method that is associated with an individual object.
What is a class variable?
Variables that are shared by every instance of a class.
What does the declaration Circle[] x = new Circle[10] imply?
x contains a reference to an array and each element can hold a reference to a Circle object.
What keyword is used to refer to the current instance of a class?
this.