Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA 1. Which of the following are good candidates for instance variables for a class that you would define? A. Variables (like loop counters or

JAVA

1.

Which of the following are good candidates for instance variables for a class that you would define?

A. Variables (like loop counters or temporary variables) used by most or all of your instance methods (in an attempt to avoid redeclaring these variables multiple times as locals for each instance method).
B. Private data whose values could be different for different objects of the class.
C. Constants used by the class and the client.
D.

Variables whose values are shared by all class objects.

2.

A linear search algorithm is written (as in the modules, for example) which searches an array for some user-defined value, clientData. If clientData is stored in the array, it returns its array position, and if not found, it returns -1 (again, just like in the modules). Assume the array to be searched has 100 data elements in it. (Check all that apply):

[NOTE: due to common off-by-one interpretations when counting such things, if your predicted answer is within one (+1 or -1) of a posted option below, you can assume your prediction and the choice you are looking at are equivalent and check that option.]

A It might return to the client with an answer after only one comparison of data.
B It will never require more than 100 comparisons of data before it returns.
C It may require as many as 100 comparisons of data before it returns.
D It will always return with an answer in 50 or fewer comparisons of data.
E

It will always return with an answer in 10 or fewer comparisons of data.

3.

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) { Planet myHome; myHome = Planet.VENUS; }
 b. public void memberMethod() { Planet myHome = EARTH; }
 C. public static void main(String[] args) { SolarSystem.Planet myHome; myHome = SolarSystem.Planet.VENUS; }
 D. public void memberMethod() { Planet myHome = Planet.NEPTUNE; }
 E. public static void main(String[] args) { SolarSystem sol = new SolarSystem(); sol.memberMethod(); }

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago