Test 3 chapters 5, 6, and 7

Ace your homework & exams now with Quizwiz!

Subscripting of an array always starts with __________.

0

When an array is passed to a method __________.

All of these are true it is passed just as any other object would be passed a reference to the array is passed the method has direct access to the original array

Write a statement that creates an ArrayList object to hold Rectangle objects and assigns its address to a reference variable named "rectangles".

ArrayList <Rectangle> rectangles = new ArrayList<Rectangle>();

An access specifier indicates the data type of a value returned by a method.

False

If a[] and b[] are two integer arrays, the expression a == b compares the array contents.

False

In the method header, the method modifier public means that only other members of the same class can access it.

False

Using the ArrayList of the previous two problems with reference variable named "rectangles", write code to get the 3rd Rectangle from the rectangles array and store it in a reference variable called "box" of type Rectangle.

Rectangle box = rectangles.get(2);

Write the code needed to declare an array of Strings and initialize it with the names of movie or book characters using an array literal.

String[] names = ("Frodo", "Sam", "Bilbo", "Gandalf");

A class is not an object. It is a description of an object.

True

A parameter variable's scope is the method in which the parameter is declared

True

An ArrayList object automatically expands in size to accommodate the items stored in it.

True

Declaring an array reference variable does not create an array.

True

Methods are commonly used to break a problem into small manageable pieces.

True

No statement outside the method in which a parameter variable is declared can access the parameter by its name.

True

Objects in an array are accessed with subscripts, just like any other data type in an array.

True

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

True

When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.

True

You must have a return statement in a value-returning method.

True

Consider the following code. int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8; What will be the results after the code above is executed?

a = 5

In a general sense, a method is __________.

a collection of statements that perform a specific task

What does the following UML diagram entry mean? + setHeight(h : double) : void

a public method with a parameter of data type double that does not return a value

When an object, such as a String, is passed as an argument it is __________.

actually a reference to the object that is passed

Consider the following statement import java.util.Scanner; This is an example of ____________ .

an explicit import statement

Values stored in local variables __________.

are lost between calls to the method in which they are declared

The __________ indicates the number of elements the array can hold.

array's size declarator

A constructor __________.

has the same name as the class

Another term for an object of a class is a(n) __________.

instance

A search algorithm __________.

is used to locate a specific item in a collection of data

When a primitive data type argument is passed to a method __________.

its value is copied into the method's parameter variable

You should always document a method by writing comments that appear __________.

just before the method's definition

Each array in Java has a public field named __________ that contains the number of elements in the array..

length

If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

numbers[r].length

In the header of a method, the method name is always followed by __________.

parentheses

Assume that the Rectangle class has a constructor represent by the following UML diagram entry +Rectangle(width : double, height : double) Add a new Rectangle object with width set to 2, and height set to 5 to the rectangles ArrayList of the previous question.

rectangles.add(new Rectangle(2.0, 5.0));

Which of the following is not part of a method header?

semicolon

The header of a value-returning method must specify __________

the data type of the return value

When an object is passed as an argument to a method, what is passed into the method's parameter variable?

the object's memory address

A class's responsibilities include __________.

the things a class is responsible for knowing the actions a class is responsible for doing both of these

To indicate the data type of a variable in a UML diagram, you enter __________.

the variable name followed by a colon and the data type

Two or more methods in a class may have the same name as long as __________.

they have different parameter lists

The sequential search algorithm __________.

uses a loop to sequentially step through an array, starting with the first element

Data hiding is accomplished in Java by __________.

using the private access specifier on the class fields

Which type of method performs a task and sends a value back to the code that called it?

value-returning

The private access specifier for a field in a class indicates that the field may not be accessed by statements outside the class.

True

When an array of objects is declared but not initialized, the array values are set to null.

True

Write the Java code needed to implement the Triangle class shown in the UML diagram below. Write complete code for all methods including constructors, getters, and setters. Assume that "b" is associated with "base" and "h" is associated with "height". For the getArea method return the area of the Triangle using the base and height fields.

public class Triangle { private double base; private double height; public Triangle() { base = 0; height = 0.0; } public Triangle(double b, double h) { base = b; height = h; } public double getBase() { return base; } public void setBase(double b) { base = b; } public double getHeight() { return height; } public void setHeight(double h) { height = h; } public double getArea() { return base * height / 2.0; } }

Consider the following code and assume that the array, numbers, has been declared and initialized earlier in the program. double value = 0; for (int a = 0; a < numbers.length; a++) { value += numbers[a]; } value /= numbers.length; What would be the result after the code above is executed?

value contains the average of all the values in the array, numbers.

What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; }

180

To create a method, you must write its __________.

definition

Which symbol indicates that a member is public in a UML diagram?

+


Related study sets

Public Speaking Chapter 7-9 Questions

View Set

January ACC 201 Connect Questions

View Set

CHAPTER 54 Care of Patients with Esophageal Problems

View Set

CIS330 Linux Chapter 7 Working with the BASH Shell Part 2

View Set