How many times does the body of this while loop execute?
int x = 0;
while (x / 3 < 3)
{
x++;
}
9
What code declares a two-dimensional array of doubles named "hours" with 10 rows and 7 columns?
double[][] hours = new double[10][7];
The extends keyword applies to...
a class inheriting from another class; defines a child class from its parent.
What does the "final" keyword indicate?
This field/class cannot be modified.
A class called Quiz has a method with the following signature:
public static void displayStats(int numGrades)
How would you call the displayStats method?
Quiz.displayStats(25);
How many iterations does the following loop encounter?
7
When referring to arrays, what is an element?
The value at a certain position in the array.
How do you instantiate an object from an abstract class?
You can't- at least not directly.
To which classes does the protected keyword grant access?
The class itself, any subclasses, and any classes in the same package.
We have used the following constant a couple of times in this course:
Integer.MAX_VALUE
What kind of value is this?
class variable; a public constant in the Integer class
What output is produced by the following code?
Hello
Hello
Given the following two-dimensional array declaration:
double[][] grades = new double[30][10];
What will the following code output?
System.out.println(grades.length);
30
What fields and methods are inherited by a subclass?
(Hint: access modifiers?)
Protected and public
Which keyword(s) is/are used when a variable belongs to the entire class?
static
Given the following code:
How would you call the power method to calculate 3^5 (3 to the 5th power) and set it to an integer variable named 'number'?
int number = Calc.power(3, 5);
What output is produced by the following code?
0
count after loop = 1
Given the following array, what would the values in numbers be changed to after only one pass of selection sort?
int[] numbers = {6. 3, 4, 7, 9, 2, 5};
{2, 3, 4, 7, 9, 6, 5}
In object-oriented programming (OOP), what is the principle of overriding?
A method from a parent class with the same signature (name, parameters, return type) is redefined by a child class.
What code would declare and initialize a constant called SIZE to represent the value 30 for the length of an array?
public static final int SIZE = 30;
What is the purpose of a parameterized constructor?
To instantiate a new object by initializing its instance variables with the given arguments.
What output is produced by the following statements?
Positive
-100
What code will declare (and initialize) a two-dimensional array named "settings" with the same layout as the table of data below?
int[][] settings = { {12, 24, 32, 21}, {14, 67, 87, 65},{19, 1, 24, 12} };
Which of the following are properties of an abstract class?
A) An abstract class cannot have instance variables and methods.
B) An abstract class can have instance variables and methods.
C) An abstract class is used for inheritance purposes
D) An abstract class cannot be instantiated.
E) There is no public constructor provided by an abstract class.
F) The constructor should initialize all instance variables.
B) An abstract class can have instance variables and methods.
C) An abstract class is used for inheritance purposes
D) An abstract class cannot be instantiated.
E) There is no public constructor provided by an abstract class.
The extends keyword applies to:
1) a member variable
2) a method of the class
3) an expression
4) a class inheriting from another class
5) the overridden toString method
4
What is the correct implementation of the equals method of the following class?