Click the Start button when you are ready to begin the exam, but only then as you can only take the exam once. Click on the Next button to go to the next question. Click on the Previous button to go to the previous question. Use the number buttons to jump to a particular question. Click the Pause button to pause the exam (you will not be able to see the questions when the exam is paused). Click on the Finish button after you have answered all the questions. The number correct, number wrong, and number skipped will be displayed.
Consider the following declaration for a class that will be used to represent points in time. Which of these options correctly implement ββaddMinutes()ββ?
Implementations II and III are correct, but implementation I is not. Implementation I does not account for values of additionMinutes that push the minute count above 60.
A sequential search loops through the elements of an array starting with the first and ending with the last and returns from the loop as soon as it finds the passed value. It has to check every value in the array when the value it is looking for is not in the array. This would take 10 executions of the loop.
I. Methods from a superclass can be used in a subclass without rewriting or copying code.
II. An object from a subclass can be passed as an argument to a method that takes an object of the superclass
III. Objects from subclasses can be stored in the same array
IV. All of the above
V. None of the above
In fact, all of the reasons listed are valid. Subclasses can reuse methods written for superclasses without code replication, subclasses can be stored in the same array, and passed as arguments to methods meant for the superclass. All of which make writing code more streamlined.
II is also valid. In some cases a single method is applicable for a number of subclasses, and inheritance allows you to pass objects of the subclasses to the same method instead of writing individual methods for each subclass.
II and III are also valid, in some cases a single method is applicable for a number of subclasses, and inheritance allows you to pass all the subclasses to the same method instead of writing individual methods for each subclass and you might want to store subclasses together in a single array, and inheritance allows for this.
This canβt be true because a[1]--; means the same as a[1] = a[1] - 1; So the 3 will become a 2. Parameters are all pass by value in Java which means that a copy of the value is passed to a method. But, since an array is an object a copy of the value is a copy of the reference to the object. So changes to objects in methods are permanent.
The variable i loops from 1 to 6 i = 1, t = 10, a = 4, b = 9 i = 2, t = 4, a = 11, b =2 i = 3, t = 11, a = 5, b = 8 i = 4, t = 5, a = 12, b = 1 i = 5, t = 12, a = 6, b = 7 i = 6, t = 6, a = 13, b = 0
This would only be correct if we had s1 = s2; after s2.toLowerCase(); was executed. Strings are immutable and so any change to a string returns a new string.
This would be correct if we had s1 = s3; after s3.toUpperCase(); was executed. Strings are immutable and so any change to a string returns a new string.
int[][] matrix = { {1,1,2,2},{1,2,2,4},{1,2,3,4},{1,4,1,2}};
int sum = 0;
int col = matrix[0].length - 2;
for (int row = 0; row < 4; row++)
{
sum = sum + matrix[row][col];
}
int [][] mat = new int [3][4];
for (int row = 0; row < mat.length; row++)
{
for (int col = 0; col < mat[0].length; col++)
{
if (row < col)
mat[row][col] = 3;
else if (row == col)
mat[row][col] = 2;
else
mat[row][col] = 1;
}
}
This will fill mat with 3 if the row index is less than the column index, 2 if the row index is equal to the column index, and a 1 if the row index is greater than the column index.
Assume that temp is an int variable initialized to be greater than zero and that a is an array of type int. Also, consider the following code segment. Which of the following will cause an infinite loop?
When a contains a value that is less than or equal to zero, then multiplying that value by 2 will never make the result larger than the temp value (which was set to some value > 0), so an infinite loop will occur.
The first test is false since num2 is less than 0 and for a complex conditional joined with And (&&) to be true both expressions must be true. Next, else if ((num2<0) || (num1<0)) is executed and this will be true since num2 is less than 0 and for a complex conditional joined with Or (||) only one of the expressions must be true for it to execute.