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.
public class C1
{
private int num;
private String name;
public C1(int theNum)
{
num = theNum;
}
public C1(String theName)
{
name = theName;
}
// other methods not shown
}
public class C2 extends C1
{
// methods not shown
}
Possible constructors
I. public C2 () { }
II. public C2 (int quan) {super (quan); }
III. public C2 (String label) { super(label); }
If there is not a call to super as the first line in a child class constructor then super() is automatically added. However, this will cause a problem if the parent class does not have a no argument constructor.
C2 constructors can call C1 constructors using the super keyword. In fact this call is automatically added to C2 constructors as the first line in any C2 constructor if it isnβt there.
If we assume that x == y is the same than using it in the full expression should return true. But, if x is equal to y you would get (true && false) || (false && true) which is false.
How can this be true? Remember that && requires both expressions to be true in order to return true. You can think of (x==y && !(x==y)) as A && !A which is always false. You can think of ( x!=y && !(x!=y) as B && !B which is always false.
This can be simplified to (A && !A) || (B && !B) which is (false || false) which is false. You can think of (x==y && !(x==y)) as A && !A which is always false. You can think of ( x!=y && !(x!=y) as B && !B which is always false.
This is a selection sort that is starting at end of the array and finding the largest value in the rest of the array and swapping it with the current index.
This would be correct if this was starting at index 0 and finding the smallest item in the rest of the array, but this starts at the end of the array instead and finds the largest value in the rest of the array.
Consider the following declarations. If matrix is initialized to be: { {-1, -2, 3},{4, -5, 6}}. What will the values in matrix be after changeMatrix(matrix) is called?
This would be true if none of the values in the matrix were changed. But, this will change the value to the absolute value when the row and column index are the same.
Which of the following correctly shows the iterations of an ascending (from left to right) insertion sort on an array with the following elements: {6,3,8,5,1}?
An insertion sort will skip the first position and then loop inserting the next item into the correct place in the sorted elements to the left of the current item.
The general formula for the number times a loop executes is the last value - the first value + 1. The outer loop will execute 3 times (2-0+1) and the inner loop will execute 7 times (7-1+1) so the total is 3 * 7 = 21.
The first test will fail since num1 is less than 0, the second test will fail since num2 is greater than 0, the third test will also fail since num2 is greater than 0, which leads to the else being executed.
Strings are immutable in Java which means they never change. Any method that looks like it changes a string returns a new string object. Since s1 was never changed to refer to a different string it stays the same.
Given the following array declaration and the fact that Animal is the parent class for Bird, Dog, Pig, Cat, and Cow, what is output from looping through this array of animals and asking each object to speak()?
Animal[] a = { new Cat(), new Cow(), new Dog(), new Pig(), new Bird() }
Animal that has a method speak() which returns "Awk".
Bird doesnβt have a speak method
Dog has a speak method that returns "Woof"
Pig doesnβt have a speak method
Cow has a speak method that returns "Moo"
Cat has a speak method that returns "Meow"
This would be true if Pig had a speak method that returned "Oink" and Bird had a speak method that returned "Tweet", but they do not. The inherited speak method will be called in Animal.
The value of a[1] will be doubled since passing a copy of the value of s is a copy of the reference to the array. The value in b wonβt change since y will be set to a copy of bβs value which is just a number.
I. Insertion sort takes longer when the array is sorted in ascending order and
you want it sorted in descending order.
II. Mergesort uses recursion.
III. Selection sort takes less time to execute if the array is already sorted
in the correct order.
Mergesort does use recursion (has a method that calls itself). Insertion sort does take longer to execute when the items to be sorted are in ascending order and you want them in descending order.