COP 2800 final review

Ace your homework & exams now with Quizwiz!

Which of the following statements will display the maximum value that a double can hold? A. System.out.println(Double.MAX_VAL); B. System.out.println(Double.MAX_VALUE); C. System.out.println(Double.MAXIMUM_VALUE);

System.out.println(Double.MAX_VALUE);

A runtime error is usually the result of a. a syntax error. b. bad data. c. a logical error. d. a compiler error.

a logical error.

To return an array of long values from a method, which return type should be used for the method? a. long[ ] b. long[ARRAY_SIZE] c. long d. array

long[ ]

Which Scanner class method reads a String? A. nextString B. nextLine C. charAt D. getLine

nextLine

The ________ method removes an item from an ArrayList at a specific index. a. pop b. remove c. deleteAt d. clear

remove

Which method is used to determine the number of items stored in an ArrayList object? a. items b. volume c. listLength d. size

size

Which symbol indicates that a member is public in a UML diagram? a. + b. # c. - d. *

+

Which of the following import statements is required to use the Character wrapper class? A. import java.lang.Char; B. import java.Char; C. import java.String; D. No import statement is required

No import statement is required

What would be displayed as a result of executing the following code? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y) a. x = 22, y = 4 b. x = 22, y = 88 c. x = 22, y = 26 d. Nothing. There is an error in the code.

Nothing. There is an error in the code.

When a character is stored in memory, it is actually the ________ that is stored. a. letter, symbol, or number b. Unicode number c. floating-point value d. ASCII code

Unicode number

A constructor a. has the return type of void. b. has the same name as the class. c. always accepts two arguments. d. always has a private access specifier.

has the same name as the class

A class that is defined inside another class is called a(n) A. enumerated class. B. helper class. C. inner class. D. nested class.

inner class

If you have defined a class, SavingsAccount, with a public static method, getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method? A. account20.getNumberOfAccounts(); B. SavingsAccount.account20.getNumberOfAccounts(); C. getNumberOfAccounts(); D. SavingsAccount.getNumberOfAccounts();

SavingsAccount.getNumberOfAccounts();

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01; a. 0.03 b. 0.05 c. 0.01 d. 0.0

0.0

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100); A. 5 B. 1 C. 4 D. 3

1

A(n) ________ is used to write computer programs. A. operating system B. application C. programming language D. pseudocode document

programming language

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC A. ClassA B. ClassB C. ClassC D. Both ClassB and ClassC are subclasses.

Class A

Which of the following is not a rule that must be followed when naming identifiers? a. After the first character, you may use the letters a-z, A-Z, an underscore, a dollar sign, or the digits 0-9. b. Identifiers can contain spaces. c. Uppercase and lowercase characters are distinct. d. The first character must be one of the letters a-z, A-Z, an underscore, or a dollar sign.

Identifiers can contain spaces.

What will be displayed after the following code is executed? String str = "RSTUVWXYZ";System.out.println(str.charAt(5));

W

In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0); A. String B. char[ ] C. char D. int

char[ ]

The ________ class is the wrapper class for the char data type. a. Character b. String c. Integer d. StringBuilder

character

When working with the PrintWriter class, which of the following import statements should you have near the top of your program? A. import java.file.*; B. import javac.io.*; C. import javax.swing.*; D. import java.io.*;

import java.io.*;

When a class implements an interface, an inheritance relationship known as ________ inheritance is established. a. implemented b. abstract c. realized d. interface

interface

One type of design tool used by programmers when creating a model of a program is a. the ALU. b. pseudocode. c. byte code. d. syntax.

pseudocode

The ________ method is used to display a message dialog. A. messageDialogShow B. showDialog C. messageDialog D. showMessageDialog

showMessageDialog

The Character wrapper class provides numerous methods for A. converting objects to primitive data types. B. performing operations with named constants. C. testing and converting character data. D. testing and converting numeric literals.

testing and converting character data.

When an argument is passed by value a. the parameter variable holds a copy of the value passed to it. b. changes can be made to the argument variable. c. the parameter variable holds the address of the argument. d. the parameter variable cannot be changed.

the parameter variable holds a copy of the value passed to it

Application software refers to a. pseudocode. b. the programs that make the computer useful to the user. c. key words. d. the operating system.

the programs that make the computer useful to the user.

What is syntax? a. the rules that must be followed when writing a program b. the symbols or words that perform operations in a program c. the words or characters that are defined by the programmer d. the words that have a special meaning in the programming language

the rules that must be followed when writing a program

Which of the following is a named storage location in the computer's memory? a. a literal b. an operator c. a variable d. a constant

a variable

When you write an enumerated type declaration, you A. are actually creating a special kind of class. B. should use the standard convention of writing the enum constants in uppercase. C. do not enclose the enum constants in quotation marks. D. All of these

All of these

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC a. ClassA b. ClassB c. ClassC d. Both ClassB and ClassC are superclasses.

ClassB

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application? a. Describe the problem domain. b. Identify all the nouns. c. Write the code. d. Refine the list of nouns to include only those relevant to the problem.

Write the code

A loop that executes as long as a particular condition exists is called a(n) ________ loop. A. conditional B. relational C. infinite D. count-controlled

conditional

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%? A. "000.0%" B. "###.##%" C. "##0.0%" D. "#0.00%"

"##0.0%"

Variables of the boolean data type are useful for a. working with very large integers. b. evaluating conditions that are either true or false. c. working with small integers. d. evaluating scientific notation.

evaluating conditions that are either true or false.

What will be displayed after the following code is executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str1); System.out.println(matches); A. The cow B. moon C. false D. true

false (no period)

When a method is declared with the ________ modifier, it cannot be overridden in a subclass. A. void B. super C. final D. public

final

The JVM periodically performs the ________ process to remove unreferenced objects from memory. a. memory sweeping b. garbage collection c. system restore d. memory shuffling

garbage collection

Which of the following import statements is required to use the StringTokenizer class? A. import java.util.StringTokenizer; B. import java.util.Scanner; C. import javax.swing.JOptionPane; D. import java.text.DecimalFormat;

import java.util.StringTokenizer;

Which of the following statements converts a String object variable named str to an int and stores the value in the variable x? a. int x - str; b. int x = Integer.integer(str); c. int x = Integer.parseInt(str); d. int x = Integer.parseInteger(str);

int x = Integer.parseInt(str);

Which of the following commands will run the compiled Java program named DoItNow? a. go DoItNow b. run DoItNow c. java DoItNow d. java DoItNow.java

java DoItNow

The central processing unit (CPU) consists of two parts which are A. the arithmetic and logic unit (ALU) and main memory. B. the control unit and main memory. C. the control unit and the arithmetic and logic unit (ALU). D. the input and output devices.

the control unit and the arithmetic and logic unit (ALU).

In the following Java statement, what value is stored in the variable name? String name = "John Doe"; a. the memory address where "John Doe" is located b. the memory address where name is located c. "name" d. John Doe

the memory address where "John Doe" is located

A method's signature consists of a. the return type, the method name, and the parameter list. b. the method name and the parameter list. c. the return type and the method name. d. the size of the method in memory.

the method name and the parameter list.

Which of the following methods returns a string representing all of the items stored in an ArrayList object? a. show b. toString c. print d. getList

toString

The boolean data type may contain which of the following range of values? A. -128 to + 127 B. -32,768 to +32,767 C. -2,147,483,648 to +2,147,483,647 D. true or false

true or false

The boolean expression in an if statement must evaluate to A. positive or negative B. degrees or radians C. left or right D. true or false

true or false

What is the value of z after the following code is executed? int x = 5, y = 28; float z; z = (float) (y / x); a. 3.0 b. 5.0 c. 5.6 d. 5.60

5

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y =50; if ( x >= y) { ans = x + 10; x -=y; } else { ans = y + 10; y += x; } a. ans = 60, x = 50, and y = 100 b. ans = 45, x = 50, and y = 0 c. ans = 60, x = 0, and y = 50 d. ans = 45, x = 50, and y = 50

ans = 60, x = 0, and y = 50

A protected member of a class may be directly accessed by a. methods in the same package. b. methods of a subclass. c. methods of the same class. d. any of these.

any of these

Because Java byte code is the same on all computers, compiled Java programs a. must be re-compiled for each different machine before they can be run. b. cannot run on computers with different operating systems. c. are nonexistent. d. are highly portable.

are highly portable

You cannot use the fully-qualified name of an enum constant for a. a boolean expression. b. a case expression. c. an argument to a method. d. Any of these

a case expression

RAM is usually A. an input/output device. B. a static type of memory, used for permanent storage. C. secondary storage. D. a volatile type of memory, used for temporary storage.

a volatile type of memory, used for temporary storage.

A(n) ________ is used as an index to pinpoint a specific element within an array. a. range b. boolean value c. element d. subscript

element

A declaration for an enumerated type begins with the ________ key word. A. enum B. enumerated C. enum type D. ENUM

enum

In order to do a binary search on an array A. the values of the array must be numeric. B. the array must first be sorted. C. you must first do a sequential search to be sure the element you are looking for is there. D. All of these are true

the array must first be sorted.

The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole. a. whole-part relationship b. mutual relationship c. enterprise d. possession

whole-part relationship

Which of the following statements will correctly convert the data type, if x is a float and y is a double? a. x = y; b. x = (float)y; c. x = float y;

x = (float)y;

What will be the values of x and y as a result of the following code?int x = 25, y = 8; x += y++; a. x = 33, y = 9 b. x = 34, y = 9 c. x = 33, y = 8 d. x = 25, y = 8

x = 33, y = 9

A ________ loop will always be executed at least once. A. posttest B. pretest C. user-controlled D. conditional

posttest

What would be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) {case 'A': discountRate = .08; break; case 'B': discountRate = .06; case 'C': discountRate = .04; default:discountRate = 0.0;} a) .04 b) 0.0 c) .08 d) .06

0.0

What will be the value of discountRate after the following statements are executed? double discountRate=0.0; int purchase=1250; char cust='N'; if (purchase >1000) if (cust == 'Y')discountRate=0.05; else discountRate=0.04; else if (purchase>750) if (cust=='Y') discountRate=0.04; elsediscountRate=0.03; elsediscountRate=0.0; a. 0.03 b. 0.05 c. 0.04 d. 0.0

0.04

How many times will the following do-while loop be executed? int x = 11; do{ x += 20; } while (x > 100); a. 5 b. 1 c. 4 d. 0

1

How many times will the following for loop be executed? for (int count = 10; count <= 21; count++) System.out.println("Java is great!"); A. 0 B. 11 C. 10 D. 12

11

What will be the value of x after the following code is executed? int x = 10; while (x < 100){ x += 100; } a. 100 b. 110 c. 90 d. 10

110

What will be the value of position after the following code is executed? int position;String str = "The cow jumped over the moon."; position = str.indexOf("ov"); a. 15 b. 18 c. 14 d. 17

15

What will be the value of x after the following statements are executed? int x=75; int y=60; if (x>y) x=x-y a. 60 b. 75 c. 135 d. 15

15

What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100){ x += y; y += 20; } a. 210 b. 110 c. 130 d. 90

210

What will be displayed after the following statements are executed?int hours = 30; double pay, payRate=10.00; pay=hours<=40 ? hours*payRate :hours*payRate*2.0; System.out.println(pay);Select one: A. 600.0 B. 300.0 C. 400.0 D. The code contains an error and will not compile.

300.0

What will be displayed after the following statements are executed?int y = 10; if (y == 10) { int x = 30; x += y; System.out.println(x); } a. 20 b. 30 c. 40 d. The code contains an error and will not compile.

40

There are ________ bits in a byte. A. 16 B. 32 C. 8 D. 4

8

What will be displayed after the following code is executed? a. ABC456 b. abc456 c. ABC d. 456

ABC

Which of the following is not part of the programming process? A. defining and modeling the problem B. testing and debugging C. entering code and compiling it D. All of these are parts of the programming process.

All of these are parts of the programming process

When an array is passed to a method A. the method has direct access to the original array. B. it is passed just as any other object would be passed. C. a reference to the array is passed. D. All of these are true.

All of these are true

For the following code, which statement is NOT true? public class Sphere { private double radius; public double x; private double y; private double z; } a. the radius is not available to code written outside the Circle class. b. the radius, x, y, and z are called members of the Circle class. c. the z is available to code that is written outside the Circle class. d. the x is available to code that is written outside the Circle class.

the z is available to code that is written outside the Circle class.

In object-oriented programming, ________ allows you to extend the capabilities of a class by creating another class that is a specialized version of it. a. data hiding b. prototyping c. code reusability d. inheritance

inheritance

A(n) ________ is a special value that cannot be mistaken as a member of a list of data items and signals that there are no more data items to be processed. a. accumulator b. terminator c. sentinel d. delimiter

sentinel

Character literals are enclosed in ________ and string literals are enclosed in ________. a. double quotes, double quotes b. single quotes, double quotes c. single quotes, single quotes d. double quotes, single quotes

single quotes, double quotes

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal? a. str1 += str2 b. str1.equals(str2) c. str1 = str2 d. str1 && str2

str1.equals(str2)

The term ________ is commonly used to refer to a string that is part of another string. A. substring B. literal C. delimiter D. nested string

substring

The data contained in an object is known as A. the classes B. the fields C. the attributes D. the methods

the attributes

In a class hierarchy a. the more general classes are toward the left of the tree and the more specialized classes are toward the right. b. the more general classes are toward the bottom of the tree and the more specialized classes are toward the top. c. the more general classes are toward the right of the tree and the more specialized classes are toward the left. d. the more general classes are toward the top of the tree and the more specialized classes are toward the bottom.

the more general classes are toward the top of the tree and the more specialized classes are toward the bottom

In an if-else statement, if the boolean expression is false a. all the statements or blocks are executed. b. the statement or block following the else is executed. c. the first statement or block is executed. d. no statements or blocks are executed.

the statement or block following the else is executed.

In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass. a. pseudocode b. a hierarchy chart c. a UML diagram d. a CRC card

a UML diagram

Enclosing a group of statements inside a set of braces creates a. a conditional statement. b. a relational operator. c. an expression. d. a block of statements.

a block of statements

A Java program must have at least one of the following: A. a comment B. a variable declaration C. a class definition D. a System.out.println(); statement

a class definition

A ragged array is A. a two-dimensional array for which the number of rows is unknown. B. a partially initialized two-dimensional array of ranged values. C. a one-dimensional array for which the number of elements is unknown. D. a two-dimensional array where the rows have different numbers of columns.

a two-dimensional array where the rows have different numbers of columns.

In all but very rare cases, loops must contain, within themselves A. a way to terminate. B. nested loops. C. arithmetic operators. D. nested decision structures.

a way to terminate.

The variable used to keep a running total in a loop is called a(n) A. sentinel. B. integer. C. accumulator. D. summation.

accumulator

A static field is created by placing the key word static a. in brackets, before the field's data type. b. after the field name. c. after the access specifier and before the field's data type. d. after the access specifier and the field's data type.

after the access specifier and before the field's data type.

When a method in the ________ class returns a reference to a field object, it should return a reference to a copy of the field object to prevent security holes. a. inner b. nested c. aggregate d. String

aggregate

Which of the following is not a valid Java comment? A. */ Comment two /* B. /* Comment four */ C. /** Comment one */ D. // Comment three

*/ Comment two /*

What will be the value of x after the following code is executed? int x, y = 15; x = y--; a. 16 b. 14 c. 15 d. 0

15

You can use the enum key word to a. specify the values that belong to the type. b. create your own data type. c. F Both of these d. F Neither of these

Both of these

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents? A. FileWriter fwriter = new FileWriter("MyFile.txt"); PrintWriter outFile = new PrintWriter(fwriter); B. PrintWriter outfile = new PrintWriter(true, "MyFile.txt"); C. PrintWriter outfile = new PrintWriter("MyFile.txt", true); D. FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

What does <String> specify in the following statement?ArrayList<String> nameList - new ArrayList<String>(); A. It specifies that everything stored in the ArrayList object will be converted to a String object. B. It specifies that String objects may not be stored in the ArrayList object. C. It specifies that the ArrayList will be converted into a String array. D. It specifies that only String objects may be stored in the ArrayList object.

It specifies that only String objects may be stored in the ArrayList object.

The original name for Java was A. HotJava. B. *7. C. JavaScript. D. Oak.

Oak

Which of the following statements will create an object from the Random class? a. Random myNumber = new Random(); b. randomNumbers() = new Random(); c. myNumber = new Random(); d. Random = new randomNumbers();

Random myNumber = new Random();

Which of the following statements correctly creates a Scanner object for keyboard input? a. Scanner keyboard(System.in); b. Scanner kbd = new Scanner(System.keyboard); c. Keyboard scanner = new Keyboard(System.in); d. Scanner keyboard = new Scanner(System.in);

Scanner keyboard = new Scanner(System.in);

Which of the following statements converts a double variable named tax to a string and stores the value in the String object named str? A. String str = double.toString(tax); B. String str = double(tax); C. String str = tax.Double.toString(str); D. String str = Double.toString(tax);

String str = Double.toString(tax);

To print "Hello, world" on the monitor, which of the following Java statements should be used? a. SystemOutPrintln('Hello, world'); b. System Print = "Hello, world"; c. system.out.println(Hello, world); d. System.out.println("Hello, world");

System.out.println("Hello, world");

Given the following declaration: enum Tree ( OAK, MAPLE, PINE )What is the fully-qualified name of the PINE enum constant? a. Tree.PINE b. enum.PINE c. PINE d. enum.Tree.PINE

Tree.PINE

Assume the class BankAccount has been created and the following statement correctly creates an instance of the class. BankAccount account = new BankAccount(5000.00); What is true about the following statement? System.out.println(account); A. A compiler error will occur. B. The method will display unreadable binary data on the screen. C. A runtime error will occur. D. The account object's toString method will be implicitly called.

The account object's toString method will be implicitly called.

What will be displayed after the following code is executed? StringBuilder strb = new StringBuilder(12); strb.append("The cow "); strb.append("jumped over the "); strb.append("moon."); System.out.println(strb); a. The cow jumped over the moon. b. The cowjumped over themoon. c. The cow jump d. 12The cow jumped over the moon.

The cow jumped over the moon.

What does the following UML diagram entry mean? + setHeight(h : double) : void a. a private method with no parameters that returns a double data type b. a private field called setHeight that is a double data type c. a public method with a parameter of data type double that does not return a value d. a public field called Height that is a double data type

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

A class becomes abstract when you place the ________ key word in the class definition. a. final b. super c. extends d. abstract

abstract

Assume you are at the operating system command line and want to use the following command to compile a program: javac MyClass.java Before entering the command you must a. close all open windows on your computer system. b. make sure you are in the same directory or folder where the MyClass.java file is located. c. execute the java.sun.com program. d. save the program with the .comp extension.

make sure you are in the same directory or folder where the MyClass.java file is located.

Which of the following expressions will generate a random number in the range of 1 through 10? a. myNumber = randomNumbers.nextInt(10); b. myNumber = randomNumbers.nextInt(10) + 1; c. myNumber = randomNumbers.nextInt(11) - 1; d. myNumber = randomNumbers.nextInt(1) + 10;

myNumber = randomNumbers.nextInt(10) + 1;

Any ________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is. A. string B. char C. static D. nonletter

nonletter

While ________ is centered on creating procedures, ________ is centered on creating objects. a. procedural programming, class programming b. routine programming, method programming c. procedural programming, object-oriented programming d. object-oriented programming, procedural programming

procedural programming, object-oriented programming

A set of programming language statements that perform a specific task is a(n) A. procedure B. object C. pseudocode chart D. source code

procedure

Computers can do many different jobs because they are A. reliable. B. programmable. C. automated. D. electronic.

programmable

All methods specified by an interface are a. protected. b. public. c. static. d. private.

public

Which of the following statements correctly specifies two interfaces? a. public class ClassA implements (Interface1, Interface2) b. public class ClassA implements Interface1, Interface2 c. public class ClassA implements Interface1 | Interface2 d. public class ClassA implements [Interface1, Interface2]

public class ClassA implements Interface1, Interface2

The binary search algorithm A. will cut the portion of the array being searched in half each time it fails to locate the search value. B. is less efficient than the sequential search algorithm. C. will, normally, have the number of comparisons that is half the number of elements in the array. D. will have a maximum number of comparisons equal to the number of elements in the array.

will cut the portion of the array being searched in half each time it fails to locate the search value.

Which of the following expressions will determine whether x is less than or equal to y? a. x >= y b. x <= y c. x =< y d. x => y

x <= y

What will be the value of x after the following code is executed? int x = 10; for ( int y = 5; y < 20; y += 5) x += y; a. 50 b. 40 c. 30 d. 25

40

Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE]; a. It will allow valid subscripts in the range of 0 through 9. b. It creates an instance of an array of ten long values. c. It declares array1 to be a reference to an array of long values. d. All of these are true.

All of these are true

What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5}; a. An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created. b. The variable x will contain the values 0 through 5. c. A compiler error will occur. d. An array of 6 values, all initialized to 0 and referenced by the variable x will be created.

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

CRC stands for A. Code, Reuse, Constancy. B. Class, Recyclability, Collaborations. C. Class, Redundancy, Collections. D. Class, Responsibilities, Collaborations.

Class, Responsibilities, Collaborations.

Which of the following statements opens a file named MyFile.txt and allows you to read data from it? A. Scanner inputFile = new Scanner("MyFile.txt"); B. File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); C. PrintWriter inputFile = new PrintWriter("MyFile.txt"); D. File Scanner = new File("MyFile.txt");

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

Scanner keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrintWriter outFile = new PrintWriter(filename); A. It allows the user to enter the name of the file that data will be written to. B. It writes to a file named filename. C. It establishes a connection with a file named filename. D. Nothing; the code contains a syntax error.

It allows the user to enter the name of the file that data will be written to.

Which of the following statements is not true about the following code? StringBulider strb = new StringBuilder("Total number of parts: "); strb.insert(23, 32); A. The starting position for the insert is 23. B. The literal number 32 will be inserted into the string. C. The ending position for the insert is 32. D. strb is a StringBuilder type object.

The ending position for the insert is 32.

What would be the result after the following code is executed? nt[] number=(40,3,5,7,8,12,10); int value=number[0]; for (int i=1; I<numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; } a. The value variable will contain the average of all the values in the numbers array. b. The value variable will contain the sum of all the values in the numbers array. c. The value variable will contain the highest value in the numbers array. d. The value variable will contain the lowest value in the numbers array.

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

For the following code, which statement is not true? public class circle{ private double radius; public double x; Private double y; } a. The radius, x, and y fields are members of the Circle class. b. The x field is available to code that is written outside the Circle class. c. The y field is available to code written outside the Circle class. d. The radius field is not available to code written outside the Circle class.

The y field is available to code written outside the Circle class.

What would be displayed as a result of executing the following code? int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house."); A. There are 5785 hens in the hen house. B. There are x5\nhens in the hen house. C. There are 583hens in the hen house. D. There are 5785 hens in the hen house.

There are 5785 hens in the hen house.

If the following is from the method section of a UML diagram, which of the statements shown is true? + equals(object2:Stock) : boolean A. This is a public method that accepts a Stock object as its argument and returns a boolean value. B. This is a private method that receives two objects from the Stock class and returns a boolean value. C. This is a public method that returns a reference to a String object. D. This is a private method that returns a boolean value.

This is a public method that accepts a Stock object as its argument and returns a boolean value.

All fields declared in an interface a. have private access. b. have protected access. c. must be initialized in the class implementing the interface. d. are treated as final and static.

are treated as final and static.

If you do not provide initialization values for a class's numeric fields, they will A. be automatically initialized to 0 B. cause a compiler error C. cause a runtime error D. contain an unknown value

be automatically initialized to 0

A block of code is enclosed in a set of a. parentheses, ( ) b. brackets, [ ] c. braces, { } d. double quotes, " "

braces { }

One or more objects may be created from a(n) a. instance. b. field. c. method. d. class.

class

In the ________ file format, when data in a spreadsheet is exported, each row is written to a line and commas are used to separate the values in the cells. A. extensible markup language B. excel binary C. data interchange D. comma separated value

comma separated value

You can concatenate String objects by using the a. concatenate method or the + operator. b. concat or trim methods. c. concatenate or join methods. d. concat method or the + operator.

concat method or the + operator

The key word new a. creates a new class. b. creates a new variable in memory. c. creates a new Java byte code file. d. creates an object in memory.

creates an object in memory

In a UML diagram you show a realization relationship by connecting a class and an interface with a a. line with an open arrowhead at one end. b. dashed line. c. dashed line with an open arrowhead at one end. d. line with an open diamond at one end.

dashed line that has an open arrowhead at one end

A characteristic of ________ is that only an object's methods are able to directly access and make changes to an object's data. a. classes b. procedures c. data hiding d. component reusability

data hiding

An item that separates other items is known as a A.terminator. B. sentinel. C. delimiter. D. partition.

delimiter

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt"); a. DiskFile.println("Calvin"); b. diskOut.println("Calvin"); c. PrintWriter.println("Calvin"); d. System.out.println(diskOut, "Calvin");

diskOut.println("Calvin");

Overloading is a. writing a method that does too much processing. b. having two or more methods with the same name but different signatures. c. writing a program that is too large to fit in memory. d. having two or more methods with the same signature.

having two or more methods with the same name but different signatures

Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)? a. if (temp > 0 && temp < 100) b. if (temp > 0 || temp < 100) c. if (temp >= 0 && temp <= 100) d. if (temp >= 0 || temp <= 100)

if (temp >= 0 && temp <= 100)

Which statement tells the compiler where to find the JOptionPane class and makes it available to your program? A. import JOptionPane; B. import Java.Swing.JOptionPane; C. import javax.swing.JOptionPane; D. import javax.JOptionPane;

import javax.swing.JOptionPane;

Another term for an object of a class is a(n) A. method. B. instance. C. member. D. access specifier.

instance

When an object is created, the attributes associated with the object are called a. instance methods. b. class instances. c. instance fields. d. fixed attributes.

instance fields.

Methods that operate on an object's fields are called a. instance variables. b. instance methods. c. public methods. d. private methods.

instance methods

Which of the following is the operator used to determine whether an object is an instance of a particular class? a. equals b. >> c. isa d. instanceOf

instanceOf

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file? a. int number = inputFile.readInt(); b. int number = inputFile.next(); c. int number = inputFile.integer(); d. int number = inputFile.nextInt();

int number = inputFile.readInt();

When the this variable is used to call a constructor a. it can be anywhere in the constructor making the call. b. it must be the last statement in the constructor making the call. c. it must be the first statement in the constructor making the call. d. None of these. You cannot use the this variable in a constructor call.

it must be the first statement in the constructor making the call.

What will be displayed after the following code is executed? String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20, 26); System.out.println(str2); a. lazy d b. x jump c. n fox d. jumped

jumped

Validating the results of a program is important to a. make sure the program solves the original problem. b. correct runtime errors. c. correct syntax error. d. create a model of the program.

make sure the program solves the original problem.

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not. A. instances B. fields C. relationships D. methods

methods

By default, a reference variable that is an instance field is initialized to the value a. 0 b. null c. static d. void

null

If numbers is a two-dimensional array, which of the following would give the number of columns in row r? a. numbers[r].length b. numbers.length[r] c. numbers[r].length[r] d. numbers.length

numbers[r].length

A(n) ________ is a software entity that contains data and procedures. a. class b. object c. program d. method

object

Using the blueprint/house analogy, you can think of a class as a blueprint that describes a house and ________ as instances of the house built from the blueprint. A. objects B. attributes C. fields D. methods

objects

If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method. a. overloads b. inherits c. overrides d. implements

overrides

If you don't provide an access specifier for a class member, the class member is given ________ access by default. a. public b. package c. protected d. private

package

A constructor is a method that a. removes the object from memory. b. never receives any arguments. c. returns an object of the class. d. performs initialization or setup operations.

performs initialization or setup operations.

Which of the following statements declares Salaried as a subclass of PayType? A. public class PayType derives Salaried B. public class Salaried implements PayType C. public class Salaried derivedFrom(PayType) D. public class Salaried extends PayType

public class Salaried extends PayType

Which of the following is a correct method header for receiving a two-dimensional array as an argument? A. public static void passMyArray(array myArray) B. public static void passMyArray(int[ ]myArray1, int[ ]myArray2) C. public static void passMyArray(int[ ][ ] myArray) D. public static void passMyArray[ ][ ](int myArray)

public static void passMyArray(int[ ][ ] myArray)

Byte code instructions are A. syntax errors. B. another name for source code. C. machine code instructions. D. read and interpreted by the JVM.

read and interpreted by the JVM.

To indicate the data type of a variable in a UML diagram you specify a. the data type followed by the variable name. b. the class name followed by the variable name followed by the data type. c. the variable name followed by a colon and the data type. d. the variable name followed by the data type.

the variable name followed by a colon and the data type.

The only limitation that static methods have is A. they can only be called from static members of the class. B. they can refer only to nonstatic members of the class. C. they must be declared outside of the class. D. they cannot refer to nonstatic members of the class.

they cannot refer to nonstatic members of the class.

A series of words or other items of data, separated by spaces or other characters, are known as a. delimiters. b. tokens. c. strings. d. captions.

tokens

The sequential search algorithm A. returns 1 if the value being searched for is found or -1 if the value is not found. B. uses a loop to sequentially step through an array, starting with the first element. C. requires the array to be ascending order. D. All of these are true

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

Java provides a mechanism known as a ________ which makes it possible to write a method that takes a variable number of arguments. a. unary-signature template b. polymorphic byte code c. variable-length argument list d. dynamic parameter list

variable-length argument list

The ________ loop is ideal in situations where the exact number of iterations is known. a. do-while b. for c. posttest d. while

while

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached? a. while (inputFile.hasNext()) b. while (inputFile != null) c. while (inputFile.nextLine == " ") d. while (!inputFile.EOF)

while (inputFile.hasNext())

A partially filled array is normally used a. when only a very small number of values need to be stored. b. with an accompanying integer value that holds the number of items stored in the array. c. when you know how many elements will be in the array but not what the values are. d. with an accompanying parallel array.

with an accompanying integer value that holds the number of items stored in the array

The simplest way to use the System.out.printf method is A. with a format string and one format specifier. B. with a format string and one or more format specifiers. C. with only one format specifier and no format string. D. with only a format string and no additional arguments.

with only a format string and no additional arguments.

Key words are: a. words that have a special meaning in the programming language. b. words or characters representing values that are defined by the programmer. c. symbols or words that perform operations on one or more operands. d. the data names in your program.

words that have a special meaning in the programming language

What output will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y); A. x = 32, y = 4 B. x = 37, y = 5 C. x = 160, y = 80 D. x = 9, y = 52

x = 37, y = 5

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8? A. "###.0" B. "000.0" C. "#0.00%" D. "###.#"

"000.0"

________ is the term for the relationship created by object aggregation. A. Inner class B. "Has a" C. "Is a" D. One-to-many

"Has a"

What type of relationship exists between two objects when one object is a specialized version of another object? a. "has a" b. "consists of" c. "is a" d. "contains a"

"is a"

Protected class members can be denoted in a UML diagram with the ________ symbol. A. + B. - C. # D. *

#

What will be the value of bonus after the following code is executed?int bonus, sales = 10000; if (sales < 5000) { bonus = 200; } else if (sales < 7500) { bonus = 500; } else if (sales < 10000) { bonus = 750; } else if (sales < 20000) { bonus = 1000; } else { bonus = 1250; } A. 1000 B. 500 C. 750 D. 1250

1000

What will be displayed after the following statements are executed?int x = 65;int y = 55; if (x >= y) { int ans = x + y; } System.out.println(ans); A. 10 B. 100 C. 120 D. The code contains an error and will not compile.

120

What are the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2018", "-", true); A. 9, 14, 2018, and - B. - C. 9, 14, 2018 D. None of these

9, 14, 2018, and -

It is common practice in object-oriented programming to make all of a class's A. fields private. B. fields public. C. fields and methods public. D. methods private.

fields private

What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x= float[ARRAY_SIZE]; for (i=1; i<ARRAY_SIZE; i++) { x[i]=10.0; } A. A runtime error will occur. B. All the values in the array except the first will be set to 10.0. C. All the values in the array will be initialized to 10.0. D. The code contains a syntax error and will not compile.

The code contains a syntax error and will not compile

If ClassC is derived from ClassB which is derived from ClassA, this would be an example of A. multiple interfaces. B. a chain of inheritance. C. linear inheritance. D. cascading classes.

a chain of inheritance

When a method's type is an object, what is actually returned by the calling program? A.an object of that class B.a null reference C.only the values in the object that the method accessed D. a reference to an object of that class

a reference to an object of that class

Java requires that the boolean expression being tested by an if statement be enclosed in A. a set of braces. B. a set of brackets. C. a set of parentheses. D. a set of double quotes.

a set of parentheses.

Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList? A. insert B. set C. store D. add

add

When an "is a" relationship exists between objects, the specialized object has A. some of the characteristics of the general class, but not all, plus additional characteristics. B. all of the characteristics of the general object plus additional characteristics. C. none of the characteristics of the general object. D. some, but not all, of the characteristics of the general object.

all of the characteristics of the general object plus additional characteristics

A group of related classes is called a(n) A. archive. B. attachment. C. collection. D. package.

archive

A class's responsibilities include A. the things a class is responsible for doing. B. the things a class is responsible for knowing. C. both of these. D. neither of these.

both of these

After the header, the body of the method appears inside a set of A. brackets, [ ] B. braces, { } C. double quotes, " " D. parentheses, ( )

braces, { }

A loop that repeats a specific number of times is known as a(n) A. pretest. B. conditional. C. infinite. D. count-controlled.

count-controlled

A subclass can directly access A. all members of the superclass. B. only public and private members of the superclass. C. only public and protected members of the superclass. D. only protected and private members of the superclass.

only public and protected members of the superclass.

The two primary methods of programming in use today are A. procedural and object-oriented B. practical and theoretical C. desktop and mobile D. hardware and software

procedural and object-oriented

A ________ member's access is somewhere between public and private. A. final B. package C. static D. protected

protected

A cross between human language and a programming language is called A. pseudocode. B. a compiler. C. the Java language. D. the Java Virtual Machine.

pseudocode.

The end of a Java statement is indicated by a A. semicolon (;) B. bracket (}) C. asterisk (*) D. colon (:)

semicolon (;)

A ________ is a value that signals when the end of a list of values has been reached. A. token B. sentinel C. delimiter D. terminal

sentinel

Given the following method header, what will be returned from the method? public Rectangle getRectangle() A. the address of an object of the Rectangle class B. an object that is contained in the class Rectangle C. a null value D. the values stored in the data members of the Rectangle object

the address of an object of the Rectangle class

Which of the following can you use to compare two enum data values? a. the ordinal method b. the ==, >, and < operators c. the equals and compareTo methods d. the moreThan, lessThan, and equalsTo methods

the equals and compareTo methods

A flag may have the values A. of any range of integers. B. of any Unicode character. C. true or false. D. defined or undefined.

true or false

If object1 and object2 are objects of the same class, to make object2 a copy of object1 A. write a method for the class that will make a field by field copy of object1 data members into object2 data members. B. use an assignment statement to make object2 a copy of object1. C. use the default constructor to create object2 with object1 data members. D. use the copy method that is a part of the Java API

write a method for the class that will make a field by field copy of object1 data members into object2 data members.


Related study sets

Pellico Ch. 10: Nursing Management: Patients With Chest and Lower Respiratory Tract Disorders

View Set

Field Tech III - IV Conventional-TCP/IP PROTOCOLS (190E40-3)

View Set

Ch. 23: Infection Control (NUR 111-fundamentals book)

View Set

Chapter 14 Power, Influence, & Leadership

View Set

Spinal cord injuries nursing 4 test 1

View Set

FINAL EXAM REVIEW MANAGERIAL ACCT

View Set