Programming Final Exam

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Suppose that you create two String objects: String name1 = new String("Jordan"); String name2 = new String("Jore"); The expression name1.compareTo(name2) has a value of ____________.

-1

You save text files containing Java source code using the file extension (blank).

.java

What does the following program segment output? for(f = 0; f < 3; ++f) for(g = 0; g < 2; ++g) System.out.print(f + " " + g + " ");

0 0 0 1 1 0 1 1 2 0 2 1

What does the following program segment output? d = 0; do { System.out.print(d + " "); d++; } while (d < 2);

0 1

What does the following statement output? for(a = 0; a < 5; ++a) System.out.print(a + " ");

0 1 2 3 4

If String movie = new String("Finding Dory");, the value of movie.indexOf('i') is ____________.

1

What is the output of the following code? e = 1; while(e < 4); System.out.print(e + " ");

1

What does the following statement output? for(f = 1, g = 4; f < g; ++f, --g) System.out.print(f + " " + g + " ");

1 4 2 3

If m = 9, then after n = m++, the value of m is ____________.

10

Suppose you have declared an array as follows: int[] creditScores = {670, 720, 815}; What is the value of creditScores.length?

3

What is the output of the following code? b = 3; while(b < 6) System.out.print(b + " ");

3 3 3 3 3 3 ...

What is the output of the following code? b = 3; while(b < 6) { System.out.print(b + " "); b = b + 1; }

3 4 5

If you declare an integer array as follows, what is the value of num[2]? int[] num = {101, 202, 303, 404, 505, 606};

303

In Java, what is the value of 3 + 7 * 4 + 2?

33

4. For how many integers does the following statement reserve room? int[] value = new int[34];

34

What does the following program segment output? for(m = 0; m < 4; ++m); for(n = 0; n < 2; ++n); System.out.print(m + " " + n + " ");

4 2

If g = 5, then after h = ++g, the value of h is ____________ .

6

If m = 9, then after n = m++, the value of n is ____________.

9

The assignment operator in Java is (blank).

=

The equal to relational operator is (blank).

==

A public static method named computeSum() is located in ClassA. To call the method from within ClassB, use the statement (blank).

ClassA.computeSum();

The method parseInt() converts a(n) ____________.

String to an integer

For an alternative to the String class, and so that you can change a String's contents, you can use ____________.

StringBuilder

If a class is named Student, the class constructor name is (blank).

Student()

Which Java statement produces w on one line and xyz on the next line?

System.out.println("w\nxyz");

In which of the following situations would setting up parallel arrays be most useful?

You need to look up an employee's ID number to find the employee's last name.

The method public static boolean testValue(int response) returns (blank).

a boolean value

In Java, methods must include all of the following except (blank).

a call to another method

You need to look up an employee's ID number to find the employee's last name.

a copy of the value in the element

The keyword final used with a variable declaration indicates ____________.

a symbolic constant

Which of the following is a correct call to a method declared as public static void aMethod(char code)?

aMethod('Q');

The toString() method converts a(n) ____________ to a String. a. char b. int c. float

all of the above

In Java, you can declare an array of 12 elements and initialize ____________.

all of them

Suppose you declare an object as Book myJournal;. Before you store data in myJournal, you (blank).

also must explicitly allocate memory for it

Which of the following elements is not required in a variable declaration?

an assigned value

All Java applications must have a method named (blank).

b. main()

An escape sequence always begins with a(n) (blank).

backslash

The body of a class is always written (blank).

between curly braces

The code between a pair of curly braces in a method is a ____________.

block

A constructor ____________ overloaded.

can be

A constructor ____________ parameters.

can receive

Which assignment is correct in Java? a. char aChar = 5.5; b. char aChar = "W"; c. char aChar = 'x'; d. Two ofthese are correct.

char aChar = '*';

Nonexecuting program statements that provide documentation are called (blank).

comments

A (blank) translates high level language statements into machine code.

compiler

Joining Strings with a plus sign is called ____________.

concatenation

When data cannot be changed after a class is compiled, the data is (blank).

constant

When you initialize an array by giving it values upon creation, you ____________.

do not explicitly give the array a size

The loop that performs its conditional check at the bottom of the loop is a ____________ loop.

do...while

In a Java program, you must use (blank) to separate classes, objects, and methods.

dots

Which assignment is correct in Java? a. int value = (float) 4.5; b. float value = 4 (double); c. double value = 2.12; d. char value = 5c;

double value = 2.12;

The method that determines whether two String objects are equivalent, regardless of case, is ____________.

equalsIgnoreCase()

The String class replace() method replaces ____________.

every occurrence of a character in a String with another character.

Suppose that a String is declared as: String aStr = new String("lima bean"); The value of aStr.equals("Lima Bean") is ____________.

false

Suppose that you declare two String objects as: String word1 = new String("happy"); String word2; When you ask a user to enter a value for word2, if the user types happy, the value of word1 == word2 is ____________.

false

An object's data items are also known as (blank).

fields

Assume an array is declared as follows. Which of the following statements correctly assigns the value 100 to each of the array elements? int[] num = new int[4];

for(x = 0; x < 4; ++x) num[x] = 100;

An array is a list of data items that all ____________.

have the same type

A parallel array is one that ____________.

holds values that correspond to those in another array

The term that programmers use to describe objects that cannot be changed is ____________.

immutable

A loop that never ends is a(n) ____________ loop.

infinite

The concept of allowing a class's private data to be changed only by a class's own methods is known as (blank).

information hiding

The nonstatic data components of a class often are referred to as the (blank) of that class.

instance variables

Which of the following can be used as an array subscript?

int

The difference between int and Integer is ____________.

int is a primitive type; Integer is a class

The remainder operator (blank).

is none of the above

The first position in a String ____________.

is position zero

A sequence of characters enclosed within double quotation marks is a ____________.

literal string

A structure that allows repeated execution of a block of statements is a ____________.

loop

You send messages or information to an object through its (blank).

methods

If String myFriend = new String("Ginny");, which of the following has the value 1?

myFriend.compareTo("Hammie");

Nonambiguous, overloaded methods must have the same ____________.

name

When a block exists within another block, the blocks are ____________.

nested

To create a String object, you can use the keyword ____________ before the constructor call, but you are not required to use this format.

new

Unlike when you create a String, when you create a StringBuilder, you must use the keyword ____________.

new

Methods that you reference with individual objects are ____________.

nonstatic

What does the following statement output? for(b = 1; b > 3; ++b) System.out.print(b + " ");

nothing

Unicode value \u0000 is also known as ____________.

null

If you declare an array as follows, how do you indicate the final element of the array? int[] num = new int[6];

num[5]

An instance of a class is a(n) (blank).

object

A method variable ____________ a class variable with the same name.

overrides

Java classes are stored in a folder or ____________.

package

All method declarations contain (blank).

parentheses

Arguments to methods always appear within (blank).

parentheses

Which of the following method declarations is correct for a static method named displayFacts() if the method receives an int argument?

public static void displayFacts(int data)

A String variable name is a ____________.

reference

Array names represent ____________.

references

Which of the following could be the last legally coded line of a method declared as public static int getVal(double sum)?

return 77;

Which of the following statements determines the square root of a number and assigns it to the variable s?

s = Math.sqrt(number);

If a class named Student contains a method setID() that takes an int argument and you write an application in which you create an array of 20 Student objects named scholar, which of the following statements correctly assigns an ID number to the first Student scholar?

scholar[0].setID(1234);

The portion of a program within which you can reference a variable is the variable's ____________.

scope

Which of the following is not a primitive data type in Java?

sector

All Java programming statements must end with a (blank).

semicolon

Assuming you have declared shoeSize to be a variable of type int, which of the following is a valid assignment statement in Java?

shoeSize = 9;

A method is declared as public static void showResults(double d, int i). Which of the following is a correct method call?

showResults(12.2, 67);

When you perform arithmetic with values of diverse types, Java (blank).

simplicitly converts the values to a unifying type

The method that extracts a string from within another string is ____________.

substring()

The rules of a programming language constitute its (blank).

syntax

When you pass an array to a method, the method receives ____________.

the address of the array

Usually, you want each instantiation of a class to have its own copy of ____________.

the data fields

If a method should return an array to its calling method, ____________.

the return type in the method header is followed by square brackets

A boolean variable can hold (blank).

the value true or false

If you declare a variable as an instance variable within a class, and you declare and use the same variable name within a method of the class, then within the method, ____________.

the variable used inside the method takes precedence

If total = 100 and amt = 200, then after the statement total += amt, ____________.

total is equal to 300

If j = 5 and k = 6, then the value of j++ == k is ____________.

true

Suppose that you declare two String objects as: String word1 = new String("happy"); String word2 = new String("happy"); The value of word1.equals(word2) is ____________.

true

You must always include ____________ in a for loop's parentheses.

two semicolons

You use a (blank) to explicitly override an implicit type.

type cast

The prefix ++ is a ____________operator.

unary

You reserve memory locations for an array when you ____________.

use the keyword new

A single array element of a primitive type is passed to a method by ____________.

value

To construct a loop that works correctly, you should initialize a loop control ____________.

variable

Named computer memory locations are called (blank).

variables

You can declare variables with the same name multiple times ____________.

within a method

If a method is written to receive a double parameter, and you pass an integer to the method, then the method will ____________.

work correctly; the integer will be promoted to a double

When you declare an array, ____________.

you might reserve memory for it in the same statement


Ensembles d'études connexes

EMT Chapter 11 Airway Management

View Set

Child Development Revel Chapter 9 Module

View Set

**** me ********** im over this class

View Set

Cultural Context of Communication-Linguistic relativity

View Set