Question
Question 30 A program can be written in a messy and inefficient style and still compile without any errors and run flawlessly. A) True B)
Question 30 A program can be written in a messy and inefficient style and still compile without any errors and run flawlessly.
A) True |
B) False |
Question 31 Consider the following search method.
private static int search (int[] a, int target, int left, int right) { if (left > right) return 1 else { int midpoint = (left + right) / 2 if (a[midpoint] == target) return midpoint else if (a[midpoint] < target) return search (a, target, midpoint + 1, right) else return search (a, target, left, midpoint 1) } }
Which of the following might be described as the escape case(s) for this method to end the recursion?
A) When the midpoint value is greater than the target if (a[midpoint] > target) |
B) When the midpoint value is less than the target if (a[midpoint] < target) |
C) when there are no elements in the specified range of indices if (left > right) |
D) when the value is found in the middle of the range if (a[midpoint] == target) |
Question 32 Assume that in a given class, Villain, the instance member xCoordinate and static member newOriginX, are both are declared public, allowing the client to use them directly (that's fine -- maybe there is no illegal value for either, so no need to provide mutators). Consider legal and correct the client code (where the two objects are members of the class in question):
evilVillain1.xCoordinate = 3; evilVillain1.newOriginX = -2.2; evilVillain2.xCoordinate = 5; evilVillain2.newOriginX = -1.4;
Immediately after this code, what are the values of the instance and static members?
(We will get warnings about accessing the static member through an object vs. the class name, but for this problem we ignore the warning - it's okay.)
A) evilVillain1 has xCoordiante = 3 evilVillain2 has xCoordiante = 5 the class's static, if accessed through evilVillain1.newOrigin, = -2.2 the class's static, if accessed through evilVillain2.newOrigin, = -2.2 |
B) evilVillain1 has xCoordiante = 3 evilVillain2 has xCoordiante = 5 the class's static, if accessed through evilVillain1.newOrigin, = -1.4 the class's static, if accessed through evilVillain2.newOrigin, = -2.2 |
C) evilVillain1 has xCoordiante = 3 evilVillain2 has xCoordiante = 5 the class's static, if accessed through evilVillain1.newOrigin, = -1.4 the class's static, if accessed through evilVillain2.newOrigin, = -1.4 |
D) evilVillain1 has xCoordiante = 5 evilVillain2 has xCoordiante = 5 the class's static, if accessed through evilVillain1.newOrigin, = -2.2 the class's static, if accessed through evilVillain2.newOrigin, = -2.2 |
Question 33 Assume you are working inside the method definition of some instance method of class B - you are writing the statements that define this method. In order to call aninstance method of a class A from inside this instance method of a class B (where B and A are unrelated by inheritance to one-another), you:
A) ... must use an object of a third class, a base class of both class A and class B, for dereferencing. |
B) ... must use an object of class A for dereferencing the method call. |
C) ... must use an object of class B for dereferencing the method call. |
D) ... can call the method without any object used for dereferencing. |
Question 34 Another name for an object is a(n)...
A) array |
B) class |
C) instance |
D) exception |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started