- 29%

Java Foundations 3rd Edition By John Lewis-Test Bank

Original price was: $35.00.Current price is: $24.97.

  Format: Downloadable ZIP File

  Resource Type: Test bank

  Duration: Unlimited downloads

  Delivery: Instant Download

Original price was: $35.00.Current price is: $24.97.

(-29%)
Add to wishlistAdded to wishlistRemoved from wishlist 0

Quiz Bank For Java Foundations Third Edition By John Lewis

ISBN-10:0133370461 , ISBN-13:978-0133370461

Chapter 3: Utilizing Lessons and Objects

Several Questions of Selection:

1) The ________________ operator serves the purpose of creating an object.

a) static

b) new

c) +

d) –

e) none of the above

Answer: b

Explanation: The new operator is utilized for object creation. There is no static operator, and the + and – operators are for arithmetic operations (although the + operator can also be used for String concatenation).

2) A specific method invoked to initialize an object during instantiation is known as a ___________________.

a) new method

b) dot operator

c) creator

d) constructor

e) destructor

Answer: d

Explanation: The constructor is responsible for initializing an object during instantiation. The dot operator is used to access object methods. There is no “new” method – new is an operator. Java also does not have “creators” or “destructors”.

3) Which of the following is an incorrect way to create a String object?

a) String title = new String(“Java Software Solutions”);

b) String name = “John Lewis”;

c) String empty = “”;

d) String alsoEmpty = new String(“”);

e) all of the above are correct

Answer: e

Explanation: Choices a and d depict the standard way of instantiating a String object. Choice d creates the empty string. Choices b and c use a shortcut notation specific to creating a String object.

4) Assume that we have a Random object referenced by a variable named generator. Which of the following lines will generate a random number in the range 5-20 and assign it to the integer variable randNum?

a) randNum = generator.nextInt(15) + 5;

b) randNum = generator.nextInt(15) + 6;

c) randNum = generator.nextInt(16) + 5;

d) randNum = generator.nextInt(16) + 6;

e) none of the above

Answer: c

Explanation: When the nextInt() method is called with 16 as a parameter, it will return a number in the range 0 to 15. Adding 5 to this random number will generate a number in the range 5 to 20.

5) Which of the following classes contain the getCurrencyInstance() method?

a) String

b) NumberFormat

c) DecimalFormat

d) Math

e) none of the above

Answer: b

Explanation: The NumberFormat class includes the getCurrencyInstance() method.

6) Which of the following expressions correctly compute 5 + 26?

a) result = 5 + 2^6;

b) result = 5 + 2*exponent(6);

c) result = 5 + 2*Math.exponent(6);

d) result = 5 + Math.pow(2, 6);

e) none of the above

Answer: d

Explanation: Choice a is incorrect as Java does not have an exponential operator for primitive types. Choices b and C are incorrect as there are no methods named exponent in the java.lang package or the Math class. Choice c correctly uses the Math.pow method to compute the expression.

7) Consider the following code snippet:

Random generator = new Random();
int randNum = generator.nextInt(20) + 1;

Which of the following statements is true after executing these lines?

a) randNum will hold a number between 1 and 20 inclusive.

b) randNum will hold a number between 0 and 20 inclusive.

c) randNum will hold a number between 1 and 21 inclusive.

d) these lines will not be executed due to a compiler error.

e) none of the above

Answer: a

Explanation: When nextInt() is called with a parameter of 20, it will return an integer between 0 and 19 inclusive. Adding one to this will result in a number between 1 and 20 inclusive.

8) Which of the following represents the correct way to create a NumberFormat object that formats numbers as percentages?

a) NumberFormat fmt = new NumberFormat(%);

b) NumberFormat fmt = new NumberFormat(“%”);

c) NumberFormat fmt = NumberFormat.getPercentInstance();

d) NumberFormat fmt = new PercentNumberFormat();

e) none of the above

Answer: c

Explanation: The NumberFormat class uses factory methods to construct objects. The new operator is implicitly called in this case. The factory method used here is getPercentInstance(). Therefore option c is correct. Options a and b are incorrect as they explicitly call the new operator. Option d is incorrect as there is no PercentNumberFormat class that can be called with the new constructor.

9) Which of the following is a valid declaration of an enumerated type for the suits of a deck of cards?

a) enumerated type Suit = { hearts, spades, diamonds, clubs };

b) enum Suit {hearts, spades, diamonds, clubs };

c) enum Suit {hearts, spades, diamonds, clubs }

d) enumerated type Suit = {hearts, spades, diamonds, clubs };

e) enum Suit = { hearts, spades, diamonds, clubs }

Answer: c

Explanation: Option c represents the correct syntax for declaring an enumerated type named Suit that can take one of the values hearts, spades, diamonds, or clubs.

10) ____________________ is the automatic conversion between a primitive value and a corresponding wrapper object.

a) Generating

b) Aliasing

c) Number formatting

d) Static invocation

e) Autoboxing

Answer: e

Explanation: Autoboxing facilitates the automatic conversion between a primitive value and a corresponding wrapper object. The other four answers are incorrect.

Textbook Related Quiz Banks

Quiz Bank For Investment Analysis And Management 12th Edition B Charles

Quiz Bank For Investments Analysis And Management 3rd Canadian Edition By W. Sean Cleary

User Reviews

0.0 out of 5
0
0
0
0
0
Write a review

There are no reviews yet.

Be the first to review “Java Foundations 3rd Edition By John Lewis-Test Bank”

Your email address will not be published. Required fields are marked *

Java Foundations 3rd Edition By John Lewis-Test Bank
Java Foundations 3rd Edition By John Lewis-Test Bank

Original price was: $35.00.Current price is: $24.97.

Test Banks Go
Logo
Shopping cart