Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 13 A constructor is used to: A) ... declare the member variables of a class. B) ... initialize the instance members of a class.

Question 13 A constructor is used to:

A) ... declare the member variables of a class.
B) ... initialize the instance members of a class.
C) ... initialize the static members of a class.
D) ... initialize both instance and static members of a class.

Question 14 Which of the below options describe a design in which class B is a derived class of base class A?

A) Class A is a Jacket something that is worn to keep a person warm.

Class B is an JacketSleeve (something that goes into a Jacket).

B) Class A is an InventoryItem, something a business stocks and sells to a customer. It has an item number and price.

Class B is an MensApparelItem, which is stocked and sold by a department store like Macy's.

C) Class A is an MensApparelItem, which is stocked and sold by a department store like Macy's.

Class B is an InventoryItem, something a business stocks and sells to a customer. It has an item number and price.

D) Class A is an Sleeve, something that goes into a shirt, jacket or sweater.

Class B is a Jacket.

Question 15 Assume DerivedClass is derived from BaseClass and we have a reference variable for each: subRef and baseRef, respectively. Assume baseRef has been instantiated but subRef has not.

True or False: At this point in the program, we can do the following without a compiler error:

 subRef = (DerivedClass) baseRef;
A) True
B) False

Question 16 Consider both of the following approaches to the binary search:

Approach A

private static int search (int[] a, int searchValue) { int left = 0 int right = a.length1 while (left <= right) { int midpoint = (left+right)/2 if (a[midpoint] == searchValue) return midpoint else if (a[midpoint] < searchValue) left = midpoint + 1 else right = midpoint 1 } return 1 }

Approach B

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 approach uses recursion? Explain why Approach B has more parameters than Approach A.

A) Approach B uses recursion. Approach B has left and right parameters because they are not defined locally in the method itself. Either defining these values in the parameters or locally in the method is a matter of preference and has no bearing on the outcome. These values are needed to define the search area, either by increasing the value of left or decreasing the value of right.
B) Both Approach A and Approach B use recursion. The additional parameters are not necessary and should be removed to make the method implementation more readable.
C) Approach A uses recursion. Approach B requires the left and right parameters because they are needed in the process of iteration to reduce the search area, either by increasing the value of left or decreasing the value of right.
D) Approach B uses recursion. Approach B includes the additional left and right parameters because they are required in the process of recursion to reduce the search area, either by increasing the value of left or decreasing the value of right when a recursive call is made.

Question 17 Assume that we have defined an enum type Planet and an instance memberMethod(), both in class SolarSystem:

class SolarSystem { public enum Planet { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE } void memberMethod() { ... } } 

Also assume, as usual, that, a totally separate and unrelated class, Foothill, contains the client main().

Which statements have enum-related compiler errors? Assume that these are isolated statements in otherwise sensible, error-free programs and that there are no variables with the names MERCURY,... NEPTUNE anywhere in our program other than the ones seen above.

(There may be more than one correct choice.)

 A) public static void main(String[] args) { SolarSystem.Planet myHome; myHome = SolarSystem.Planet.VENUS; }
 B) public void memberMethod() { Planet myHome = EARTH; }
 C) public void memberMethod() { Planet myHome = Planet.NEPTUNE; }
 D) public static void main(String[] args) { Planet myHome; myHome = Planet.VENUS; }
 E) public static void main(String[] args) { SolarSystem sol = new SolarSystem(); sol.memberMethod(); }

Question 18 Consider the following 2-D array allocation:

 Dog[][] lilikoi = new Dog[4][6]; 

Check the true statements.

A) We can redefine the Dog object in the bottom row and right-most column of lilikoi[][] using the notation:

 lilikoi[4][6] = new Dog();
B) The original array declaration, with no additional instantiation, will create 24 Dog objects.
C) lilikoi[][] is considered to have 4 rows and 6 columns
D) The original array declaration, with no additional instantiation, will create 24 Dog references.
E) The original array declaration, with no additional instantiation, will create 24 doubles.
F) for ( row = 0; row < lilikoi.length; row++) for ( col = 0; col < lilikoi[row].length; col ++) lilikoi[row][col] = new Dog();

will instantiate 24 objects for array lilikoi[][].

Question 19 Which describe a design in which B is a derived class of base class A? (Check all that apply.)

A) Class A is an AutoPart which goes into a car or truck. It has a part number, weight and price.

Class B is a Automobile -- either a Car or a Truck.

B) Class A is Building that shelters people and equipment.

Class B is a HighRise, which has a minimum of five floors (stories) with stairs and elevators and utilized by government agencies, condo complexes and companies.

C) Class A is an AutoPart which goes into a car or truck. It has a part number, weight and price.

Class B is a FuelInjector, a special kind of part that goes into cars and trucks.

D) Class A is Building that shelters people and equipment.

Class B is a CityVisualizer which will render one or more Buildings in 3D on a computer or smart phone screen.

Question 20 If a base class reference, p, points to a derived class instance, and both base and derived classes have a public method void doIt() which takes no parameters, then p.doIt() will ...: (one or more correct answer)

A) ... invoke the base class version, because type coercion was not used to first coerce the base class reference to a derived class type.
B) ... invoke the base class version, because the base class reference only knows about the base class version of doIt().
C) ... invoke the derived class version, because it is the object pointed to that determines which method is called.

Question 21 If we operate bitwise on the following two decimal integers, as indicated, what are the two resulting decimal answers?

9 bitwise-or 7 9 bitwise-and 7

A) 15 1
B) 12 2
C) 12 1
D) 15 2
E) 16 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago