CS180 Final

Ace your homework & exams now with Quizwiz!

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

a reference to the String object containing "ghi"

In the following code, System.out.println(num) is an example of __________. double num = 5.4; System.out.println(num);

a void method

What type of method does not return any data to the caller?

a void method

What type of method performs a task and then terminates?

a void method

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

a=5

This is a method that gets a value from a class's field, but does not change it.

accessor

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

actually a reference to the object that is passed

To insert an item at a specific location in an ArrayList object, you use this method.

add

Which of the following statements about constructors is true? a) constructors have the sale name as the class b) constructors are typically public c) constructors do not have a return type d) all of the above

all of the above

Local variables __________.

are hidden from other methods may have the same name as local variables in other methods lose the values stored in them between calls to the method in which the variable is declared

A value that is passed into a method when it is called is known as a( n) __________.

argument

Values that are sent into a method are called __________.

arguments

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0 through 14

What value will be returned from the following method? public static double methodA() { double a = 8.5 + 9.5; return a; }

18.0

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

What is a no args constructor?

A constructor that does not take any parameters- it gives a default value to an object when it is initialized if the user hasn't passed any information to it

What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for (int i = 1; i < ARRAY_SIZE; i++) { x[i] = 10.0; }

All will be set to 10 except first x{0}

What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};

An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created.

Methods are commonly used to

Break a problem down into small manageable pieces

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?

Control is returned to method c

________ refers to combining data and code into a single class for objects to be created from.

Encapsulation

A __________ is a part of a method that contains a collection of statements that are performed when the method is executed.

Method body

A constructor is a method that:

Performs initialization or setup operations.

This search algorithm repeatedly divides the portion of an array being searched in half.

binary search

The process of matching a method call with the correct method is known as

binding

A class's responsibilities include

both the things a class is responsible for doing and the things a class is responsible for knowing

When initializing a two-dimensional array, you enclose each row's initialization list in_____.

braces

To determine the number of items stored in an ArrayList object, you use this method.

capacity

A collection of programming statements that specify the fields and methods that a particular type of object may have

class

One or more objects may be created from a(n) ______

class

A(n) __________ can be thought of as a blueprint that can be used to create a type of __________

class / object

What specifies what data that objects can hold and the actions that objects can perform

classes

In memory, an array of String objects

consists of elements, each of which is a reference to a String object

This is a method that is automatically called when an instance of a class is created.

constructor

A class is analogous to a

cookie cutter

The body of a method is enclosed in _______

curly braces

This is automatically provided for a class if you do not write one yourself.

default constructor

Given the following method header, which of these method calls is incorrect? public void displayValue(double x, int y);

displayValue(a,b); // where a is a short and b is a long

Overloading means that multiple methods in the same class

have the same name, but different parameter lists

What appears at the beginning of a method definition?

header

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

instance

an object is a(n)

instance

When an object is created, the data associated with the object are called __________

instance fields

Methods that operate on an object's fields are called __________.

instance methods

Assume that the following method header is for a method in class A. public void displayValue(int value) Assume that the following code segments appear in another method, also in class A. Which contains a correct call to the displayValue method?

int x = 7; displayValue(x);

The __________ package is automatically imported into all Java programs

java.lang

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

length

This array field holds the number of elements that the array has.

length

The process of breaking a problem down into smaller pieces __________.

makes problems more easily solved allows for code reuse simplifies programs

a method header can contain:

method modifiers, the method return type, the method name, a list of parameter declarations

Objects normally have __________ that perform useful operations on their data, but primitive variables do not.

methods

this is method that stores a value in a field or in some other way changed the value of a field

mutator

this key word causes an object to be created in memory

new

A class is the code that describes a particular type of

object

A UML diagram does not contain __________.

object names

Most of the programming languages used today are

object-oriented

The lifetime of a method's local variable is __________.

only while the method is executing

A group of related classes is called a(n)

package

a variable that receives a value that is passed into a method is known as a

parameter

convert this UML to code: - width : double

private double width;

convert this UML to code: + getWidth() : double

public double getWidth() { return width; }

example of a value returning method header

public static int nameOfMethod()

example of a void method header

public static void nameOfMethod ()

convert this UML to code: + setWidth (w : double) : void

public void setWidth (double w) { width = w }

To delete an item from an ArrayList object, you use this method.

remove

this statement causes a method to end and sends a value back to the statement that called the method

return

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

return type

This search algorithm steps through an array, comparing each item with the search value.

sequential search

When a local variable has the same name as a field, the local variable's name does this to the field's name.

shadows

Given the following method, which of these method calls is correct? public static void showProduct (int num1, double num2) { int product; product = num1 * (int)num2; System.out.println("The product is " + product); }

showProduct(10, 4.5);

Given the following method, which of these method calls is correct? public static void showProduct (double num1, int num2) { double product; product = num1 * num2; System.out.println("The product is " + product); }

showProduct(4.5, 10);

When the value of an item is dependent on other data, and that item is not updated when the other data is changed, what has the value become?

stale

You should not store calculated data, such as a Rectangle object's area, in a field because it is dependent on the current data stored in other fields. Instead, it should be recalculated each time this data is needed to avoid ________.

stale data

Instance methods do not have the keyword__________ in their headers.

static

Given that String[] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the __________ statement.

str[0].toUpperCase();

A(n) __________ is used as an index to pinpoint a specific element within an array.

subscript

A reference type variable stores a(n) __________.

the address where the value is being stored

When an array's reference variable is passed to a method

the array is passed into the method like an object ??

what does 'int num' mean in the method header public static void nameOfMethod (int num)

the data that is expected to be entered to run the method

What does 'static' mean in a method header?

the method belongs to a class, not a specific object

When an individual element of an array is passed to a method ______

the method does not have access to the original array

A parameter variable's scope (accessibility) is confined to __________.

the method in which the parameter is declared

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

the objects memory address

When you pass an argument to a method you should be sure that the argument's type is compatible with __________.

the parameter variable's data type

what does 'int' mean in the method header public static int nameOfMethod()

the type of data being returned back to the caller

Two or more methods in a class may have the same name, as long as this is different.

their parameter lists

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

this is a public method with a parameter of data type double and does not return a value

Data hiding means that critical data stored inside the object is protected from code outside the object. This is accomplished in Java by

using the private access specifier on the class fields

What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a < array1.length; a++) { value += array1[a]; }

value is the sum of all of the values in array1 (check this ***)

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

value returning

A __________ type of method performs a task and then terminates.

void

Array bounds checking happens

when the program runs

What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; }

x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x;

x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; }

z is available to code that is written outside the circle class

An array's subscripts always starts with

zero

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

+

Which symbol indicates that a member is private a UML diagram?

-

Java performs ____________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

Array bounds checking

examples of objects

Scanner, PrintWriter, Random

The __________ indicates the number of elements the array can hold

Size declarator

Java allows you to create objects of the __________ class in the same way you would create primitive variables. This is the only class for which this shortcut is allowed.

String

Which of the following statements will create a reference, str, to the String "Hello World"?

String str = "Hello World"

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

The value of the primitive type variable

What will be the results after the following code is executed? int[] array1 = new int[25]; ... // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] > value) value = array1[a]; }

The value variable will contain the highest value in the numbers array.

What would be the result after the following code is executed? int[] numbers = {40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; }

The value variable will contain the lowest value in the numbers array.

What value will be returned from the following method? public static int methodA() { double a = 8.5 + 9.5; return a; }

This is an error

A primitive type variable stores __________.

exactly one value of its declared type

this is a member of a class that holds data

field

It is common practice in object-oriented programming to make all of a class's

fields private

A class specifies the __________ and __________ for a particular type of object.

fields; methods


Related study sets

BI 207 Exam 3/ Chapter 9 Muscles

View Set

Multiple Choice De Advanced Math

View Set

BUL 3130 Business Organization Quiz

View Set

Anatomy and physiology two Del Río - the Blood

View Set