CompSci final exam

¡Supera tus tareas y exámenes ahora con Quizwiz!

The ________ statement is used to create a decision structure which allows a program to have more than one path of execution. a) block b) if c) null d) flag

B) if

Which symbol indicates that a member is private a UML diagram? a) - b) * c) # d) +

a) -

A Java source file must be saved with the extension ________. a) .java b) .javac c) .src d) .class

a) .java

By default, Java initializes array elements to ________. a) 0 b) 100 c) -1 d) 1

a) 0

Subscripting always starts with ________. a) 0 b) 1 c) -1 d) none of these

a) 0

________ works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked. a) Short-circuit evaluation b) Reverse logic c) Boolean logic d) Relational evaluation

a) Short-circuit evaluation

Which of the following statements will create a reference, str, to the String "Hello, World"? a) String str = "Hello, World"; b) string str = "Hello, World"; c) String str = new "Hello, World"; d) str = "Hello, World";

a) String str = "Hello, World";

Which of the following will format 12.7801 to display as $12.78? a) System.out.printf("$%,.2f", 12.7801); b) System.out.printf("%f", 12.7801); c) System.out.printf("%.2f$$", 12.7801); d) System.out.printf("$d", 12.7801);

a) System.out.printf("$%,.2f", 12.7801);

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

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

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

a) Unicode number

To display the output on the next line, you can use the println method or use the ________ escape sequence in the print method. a) \n b) \r c) \t d) \b

a) \n

If you attempt to use a local variable before it has been given a value, ________. a) a compiler error will occur b) the local variable will always contain the value 0 c) the results will be unpredictable d) the local variable will be ignored

a) a compiler error will occur

Which of the following is a value that is written into the code of a program? a) a literal b) an assignment statement c) an operator d) a variable

a) a literal

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

a) a logical error

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

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

Java requires that the boolean expression being tested by an if statement be enclosed in ________. a) a set of parentheses b) a set of braces c) a set of double quotes d) a set of brackets

a) a set of parentheses

A ragged array is ________. a) a two-dimensional array where the rows have different numbers of columns b) a one-dimensional array for which the number of elements is unknown c) a two-dimensional array for which the number of rows is unknown d) a partially initialized two-dimensional array of ranged values

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

In the following code, Integer.parseInt(str) is an example of ________. int num; string str = "555"; num = Integer.parseInt(str) + 5; a) a value-returning method b) a void method c) a local variable d) a complex method

a) a value-returning method

The variable used to keep a running total in a loop is called a(n) ________. a) accumulator b) sentinel c) summation d) integer

a) accumulator

When an object, such as a String, is passed as an argument it is ________. a) actually a reference to the object that is passed b) passed by value like any other parameter value c) encrypted d) necessary to know exactly how long the string is when writing the program

a) actually a reference to the object that is passed

The following statement is an example of ________. import java.util.Scanner; a) an explicit import statement b) an unconditional import statement c) a wildcard import statement d) a conditional import statement

a) an explicit import statement

Values stored in local variables ________. a) are lost between calls to the method in which they are declared b) retain their values from the last call to the method in which they are declared c) may be referenced by the calling method d) may be referenced by any other method if the method in which they are declared is a public method

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

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

a) braces, { }

A loop that repeats a specific number of times is known as a(n) ________ loop. a) count-controlled b) infinite c) conditional d) pretest

a) count-controlled

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

a) evaluating conditions that are either true or false

It is common practice in object-oriented programming to make all of a class's ________. a) fields private b) methods private c) fields public d) fields and methods public

a) fields private

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

a) for

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)

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

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

a) instance fields

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

a) instance methods

Each repetition of a loop is known as a(n) ________. a) iteration b) cycle c) execution d) lap

a) iteration

The variable that controls the number of times a loop iterates is known as a ________. a) counter variable b) loop control variable c) running total d) decrement variable

b) loop control variable

A reference variable stores a(n) ________. a) binary encoded decimal b) memory address c) object d) string

b) memory address

A group of related classes is called a(n) ________. a) archive b) package c) collection d) attachment

b) package

A special variable that holds a value being passed into a method is called a(n) ________. a) modifier b) parameter c) alias d) argument

b) parameter

A ________ loop will always be executed at least once. a) pretest b) posttest c) conditional d) user-controlled

b) posttest

A cross between human language and a programming language is called ________. a) a compiler b) pseudocode c) the Java Virtual Machine d) the Java language

b) pseudocode

Which of the following is a correct method header for receiving a two-dimensional array as an argument? a) public static void passArray(int[1,2]) b) public static void passArray(int [][]) c) public static void passArray(int[1],[2]) d) public static void passArray(int[], int[])

b) public static void passArray(int [][])

Which of the following is a correct method header for receiving a two-dimensional array as an argument? a) public static void passMyArray(int[1, 2]) b) public static void passMyArray(int[][]) c) public static void passMyArray[1][2]) d) public static void passMyArray(int[],int[] myArray)

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

Which of the following is not a part of a method call? a) method name b) return type c) parentheses d) All of these

b) return type

A ________ is a value that signals when the end of a list of values has been reached. a) terminal b) sentinel c) token d) delimiter

b) sentinel

Instance methods do not have the ________ key word in their headers. a) public b) static c) private d) protected

b) static

When the + operator is used with strings, it is known as the ________. a) assignment operator b) string concatenation operator c) addition operator d) combines assignment operator

b) string concatenation operator

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application? a)a description of the problem domain b) the code c) a refined list of nouns that include only those relevant to the problem d) all the nouns are identified

b) the code

The central processing unit (CPU) consists of two parts which are ________. a) the input and output devices b) the control unit and the arithmetic and logic unit (ALU) c) the control unit and main memory d) the arithmetic and logic unit (ALU) and main memory

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

When an object is passed as an argument to a method, what is passed into the method's parameter variable? a) the class name b) the object's memory address c) the values for each field d) the method names

b) the object's memory address

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

b) the statement or block following the else is executed.

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

b) 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 ________. a) they have different return types b) they have different parameter lists c) they have different return types but the same parameter list d) You cannot have two methods with the same name.

b) they have different parameter lists

A flag may have the values ________. a) defined or undefined b) true or false c) of any range of integers d) of any Unicode character

b) true or false

The boolean data type may contain which of the following range of values? a) -128 to + 127 b) true or false c) -2,147,483,648 to +2,147,483,647 d) -32,768 to +32,767

b) true or false

The boolean expression in an if statement must evaluate to ________. a) degrees or radians b) true or false c) positive or negative d) left or right

b) true or false

A ________ type of method performs a task and then terminates. a) value-returning b) void c) local d) simple

b) void

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; a) x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19} b) x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24} c) x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19} d) Nothing. This is a compile error.

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

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 583 hens in the hen house. b) There are 5785 hens in the hen house. c) There are x5\nhens in the hen house. d) There are 5785 hens in the hen house.

b. There are 5785 hens in the hen house. in order to get 583, there must be a parenthesis, i.e. (x+5).

Given the following method header, which of these method calls is incorrect? public void displayValue(int x, int y); a) displayValue(a, b); // where a is a short and b is a byte b) displayValue(a, b); // where a is an int and b is a byte c) displayValue(a, b); // where a is a short and b is a long d) All of these would give an error.

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

The ________ loop is ideal in situations where you always want the loop to iterate at least once. a) for b) while c) do-while d) posttest

c) do-while

Which of the following statements is invalid? a) double r = 9.4632E15; b) double r = 9.4632e15; c) double r = 2.9X106; d) double r = 326.75;

c) double r = 2.9X106;

A class specifies the ________ and ________ that a particular type of object has. a) relationships, methods b) fields, object names c) fields, methods d) relationships, object names

c) fields, methods

It is common practice to use a ________ variable as a size declarator. a) static b) reference c) final d) boolean

c) final

Overloading means that multiple methods in the same class ________. a) have the same name but different return types b) have different names but the same parameter list c) have the same name but different parameter lists d) perform the same function

c) have the same name but different parameter lists

When working with the PrintWriter class, which of the following import statements should you have near the top of your program? a) import javax.swing.*; b) import javac.io.*; c) import java.io.*; d) import java.file.*;

c) import java.io.*;

Which of the following is a valid declaration for a ragged array with five rows but no columns? a) int[][] ragged = new int[5]; b) int[][] ragged = new int[][5]; c) int[][] ragged = new int[5][]; d) int[] ragged = new int[5];

c) int[][] ragged = new int[5][];

To compile a program named First you would use which of the following commands? a) java First.java b) javac First c) javac First.java d) compile First.javac

c) javac First.java

Which of the following will compile a program called ReadIt? a) java ReadIt.java b) java ReadIt.javac c) javac ReadIt.java d) javac ReadIt.javac

c) javac ReadIt.java

Which of the following cannot be used as identifiers in Java? a) variable names b) class names c) key words d) objects

c) key words

Each array in Java has a public field named ________ that contains the number of elements in the array. a) size b) capacity c) length d) limit

c) length

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

c) long[]

Each different type of CPU has its own ________. a) syntax b) firmware c) machine language d) software

c) machine language

A ________ is a part of a method that contains a collection of statements that are performed when the method is executed. a) method header b) return type c) method body d) method modifier

c) method body

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not. a) fields b) relationships c) methods d) instances

c) methods

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

c) numbers[r].length

Most of the programming languages used today are ________. a) procedural b) top-down c) object-oriented d) functional

c) object-oriented

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

c) performs initialization or setup operations

The end of a Java statement is indicated by a(n) ________. a) bracket (}) b) asterisk (*) c) semicolon (;) d) colon (:)

c) semicolon (;)

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 && str2 c) str1.equals(str2) d) str1 += str2

c) str1.equals(str2)

Variables are ________. a) symbolic names made up by the programmer and once created, their values cannot be changed b) operators that perform operations on one or more operands c) symbolic names made up by the programmer that represent memory locations d) reserved words

c) symbolic names made up by the programmer that represent memory locations

The header of a value-returning method must specify ________. a) the method's local variable names b) the name of the variable in the calling method that will receive the returned value c) the data type of the return value d) All of these must be specified.

c) the data type of the return value

When an individual element of an array is passed to a method ________. a) a reference to the array is passed b) it is passed like any other variable c) the method does not have access to the original array d) All of these are true.

c) the method does not have access to the original array

An expression tested by an if statement must evaluate to ________. a) 0 or 1 b) +1 or -1 c) true or false d) t or f

c) true or false

The ________ loop allows the user to decide on the number of iterations. a) counter controlled loop b) dynamically executed loop c) user controlled loop d) infinite loop

c) user controlled loop

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

d) +

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

d) 15

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y / x); a) 8.25 b) 4 c) 0 d) 8.0

d) 8.0

To document the return value of a method you can use a ________. a) @comment tag b) @returnValue tag c) @param tag d) @return tag

d) @return tag

Which of the following is not part of the programming process? a) defining and modeling the problem b) entering code and compiling it c) testing and debugging d) All of these are parts of the programming process

d) All of these are parts of the programming process

When an array is passed to a method ________. a) it is passed just as any other object would be passed b) the method has direct access to the original array c) a reference to the array is passed d) All of these are true

d) All of these are true

Local variables can be initialized with ________. a) constants b) parameter values c) the result of an arithmetic operation d) Any of these.

d) Any of these.

A value-returning method must specify ________ as its return type in the method header. a) an int b) a double c) a boolean d) Any valid data type

d) Any valid data type

________ refers to combining data and code into a single object. a) Data hiding b) Abstraction c) The constructor d) Encapsulation

d) Encapsulation

________ refers to the physical components that a computer is made of. a) Input b) Main memory c) Control unit d) Hardware

d) Hardware

What does the following statement do? double[] array1 = new double[10]; a) It declares array1 to be a reference to an array of double values. b) It will allow valid subscripts in the range of 0 through 9. c) It creates an instance of an array of ten double values. d) It does all of these.

d) It does all of these.

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 = 26 b) x = 22, y = 4 c) x = 22, y = 88 d) Nothing. There is an error in the code.

d) Nothing. There is an error in the code.

________ operators are used to determine whether a specific relationship exists between two values. >, <, >=, <=, ==, != a) Assignment b) Arithmetic c) Logical d) Relational

d) Relational

If the following Java statements are executed, what will be displayed?System.out.println("The top three winners are\n"); System.out.print("Jody, the Giant\n"); System.out.print("Buffy, the Barbarian"); System.out.println("Adelle, the Alligator"); a) The top three winners are Jody, the Giant Buffy, the Barbarian Adelle, the Alligator b) The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino c) The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator d) The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator

d) The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator

In a general sense, a method is ________. a) a plan b) a statement inside a loop c) a comment d) a collection of statements that perform a specific task

d) a collection of statements that perform a specific task

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

d) a variable

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

d) class

In memory, an array of String objects ________. a) consists of elements, each of which is a reference to a String object b) is compressed to four bytes for each element c) must be initialized when the array is declared d) consists of an array of references to String objects

d) consists of an array of references to String objects

Variables are classified according to their ________. a) names b) values c) locations d) data types

d) data types

To create a method, you must write its ________. a) header b) return type c) body d) definition

d) definition

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

d) diskOut.println("Calvin");

If a loop does not contain, within itself, a valid way to terminate, it is called a(n) ________ loop a) for b) while c) do-while d) infinite

d) infinite

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.next(); b) int number = inputFile.integer(); c) int number = inputFile.readInt(); d) int number = inputFile.nextInt();

d) int number = inputFile.nextInt();

The lifetime of a method's local variable is ________. a) the duration of the program b) the duration of the class to which the method belongs c) the duration of the method that called the local variable's method d) only while the method is executing

d) only while the method is executing

A set of programming language statements that perform a specific task is a(n) ________. a) pseudocode chart b) source code c) object d) procedure

d) procedure

A(n) ________ is used to write computer programs. a) pseudocode document b) operating system c) application d) programming language

d) programming language

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

d) pseudocode

Which of the following is not part of a method header? a) return type b) method name c) parentheses d) semicolon

d) semicolon

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. a) str.uppercase(); b) str[0].upperCase(); c) str.toUpperCase(); d) str[0].toUpperCase();

d) str[0].toUpperCase();

Which of the following is not a primitive data type? a) short b) long c) float d) string

d) string

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

d) subscript

The scope of a public instance field is ________. a) only the class in which it is defined b) inside the class but not inside any method c) inside the parentheses of a method header d) the instance methods and methods outside the class

d) the instance methods and methods outside the class

A UML diagram does not contain ________. a) the class name b) the method names c) the field names d) the object names

d) the object names

The primitive data types only allow a(n) ________ to hold a single value. a) class b) literal c) object d) variable

d) variable

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.nextLine == " ") { ... } b) while (inputFile != null) { ... } c) while (!inputFile.EOF) { ... } d) while (inputFile.hasNext()) { ... }

d) while (inputFile.hasNext()) { ... }

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

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

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

d) words that have a special meaning in the programming language

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 = 34, y = 9 b) x = 25, y = 8 c) x = 33, y = 8 d) x = 33, y = 9

d) x = 33, y = 9

What will be the result after the following code executes? int num; string str = "555"; num = Integer.parseInt(string str) + 5; a) num will be set to 560 b) str will have a value of "560" c) The last line of code will cause an error. d) Neither num nor str will be changed.

C) The last line of code will cause an error.

When an argument is passed to a method ________. a) its value is copied into the method's parameter variable b) its value may be changed within the called method c) Both its value is copied into the method's parameter variable and its value may be changed within the called method are correct. d) Neither its value is copied into the method's parameter variable nor its value may be changed within the called method are correct.

a) its value is copied into the method's parameter variable

You should always document a method by writing comments that appear ________. a) just before the method's definition b) just after the method's definition c) at the end of the file d) only if the method is more than five lines long

a) just before the method's definition

A value that is written into the code of a program is a(n) ________. a) literal b) assignment statement c) variable d) operator

a) literal

A method ________. a) may have zero or more parameters b) never has parameter variables c) must have at least two parameter variables d) may not have only one parameter variable

a) may have zero or more parameters

The switch statement is a ________. a) multiple alternative decision structure b) nested decision structure c) sequence structure d) test expression

a) multiple alternative decision structure

Which Scanner class method reads a String? a) nextLine b) charAt c) nextString d) getLine

a) nextLine

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

a) object

In the header, the method name is always followed by ________. a) parentheses b) a return type c) a data type d) braces

a) parentheses

When you work with a ________, you are using a storage location that holds a piece of data. a) primitive variable b) reference variable c) numeric literal d) binary number

a) primitive variable

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

a) procedural programming, object-oriented programming

Software refers to ________. a) programs b) the physical components a computer is made of c) firmware d) data stored in RAM

a) programs

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

a) remove

You can use the ________ method to replace an item at a specific location in an ArrayList. a) set b) remove c) replace d) add

a) set

Before entering a loop to compute a running total, the program should first ________. a) set the accumulator variable to an initial value, often zero b) set all variables to zero c) read all the values into main memory d) know exactly how many values there are to total

a) set the accumulator variable to an initial value, often zero

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

a) single quotes, double quotes

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2? a) str1.equalsIgnoreCase(str2) b) str1.equalsInsensitive(str2) c) str1 != str2 d) str1 || str2

a) str1.equalsIgnoreCase(str2)

Internally, the central processing unit (CPU) consists of two parts which are ________. a) the control unit and the arithmetic/logic unit (ALU) b) the control unit and main memory c) the arithmetic/logic unit (ALU) and main memory d) the input and output devices

a) the control unit and the arithmetic/logic unit (ALU)

The process of breaking a problem down into smaller pieces is sometimes called ________. a) the divide and conquer method b) the scientific method c) top-down programming d) whole-into-part programming

a) the divide and conquer method

The scope of a private instance field is ________. a) the instance methods of the same class b) inside the class but not inside any method in that class c) inside the parentheses of a method header d) the method in which it is defined

a) the instance methods of the same class

A parameter variable's scope is ________. a) the method in which the parameter is declared b) the class to which the method belongs c) the main method d) All of these are true.

a) the method in which the parameter is declared

When you pass an argument to a method you should be sure that the argument's type is compatible with ________. a) the parameter variable's data type b) the method's return type c) the version of Java currently used d) IEEE standards

a) the parameter variable's data type

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

a) 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 words that have a special meaning in the programming language c) the symbols or words that perform operations in a program d) the words or characters that are defined by the programmer

a) the rules that must be followed when writing a program

Which type of method performs a task and sends a value back to the code that called it? a) value-returning b) void c) complex d) local

a) value-returning

In Java, ________ must be declared before they can be used. a) variables b) literals c) key words d) comments

a) variables

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

a) x <= y

Which of the following is not a valid Java comment? a) /** Comment one */ b) */ Comment two /* c) // Comment three d) /* Comment four */

b) */ Comment two /*

There are ________ bits in a byte. a) 4 b) 8 c) 16 d) 32

b) 8

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

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

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) File Scanner = new File("MyFile.txt"); d) PrintWriter inputFile = new PrintWriter("MyFile.txt");

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

Which is a control structure that causes a statement or group of statements to repeat? a) block b) loop c) prefix mode d) body

b) loop

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) FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter); c) PrintWriter outfile = new PrintWriter("MyFile.txt", true); d) PrintWriter outfile = new PrintWriter(true, "MyFile.txt");

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

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.

b) Identifiers can contain spaces.

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

b) Identifiers can contain spaces.

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

b) Random myNumber = new Random();

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

b) Scanner keyboard = new Scanner(System.in);

Java allows you to create objects of the ________ class in the same way you would create primitive variables. a) Random b) String c) PrintWriter d) Scanner

b) String

When a method tests an argument and returns a true or false value, it should return ________. a) a zero for true and a one for false b) a boolean value c) a zero for false and a non-zero for true d) A method should not be used for this.

b) a boolean value

A Java program must have at least one of the following. a) a comment b) a class definition c) a System.out.println(); statement d) a variable declaration

b) a class definition

Every Java application program must have ________. a) a class named MAIN b) a method named main c) at least two data types d) integer variables

b) a method named main

In the following code, System.out.println(num) is an example of ________. double num = 5.4; System.out.println(num); num = 0.0; a) a value-returning method b) a void method c) a complex method d) a local variable

b) a void method

RAM is usually ________. a) an input/output device b) a volatile type of memory, used for temporary storage c) secondary storage d) a static type of memory, used for permanent storage

b) a volatile type of memory, used for temporary storage

In all but very rare cases, loops must contain, within themselves ________. a) nested loops b) a way to terminate c) arithmetic operators d) nested decision structures

b) a way to terminate

Which of the following is a software entity that contains data and procedures? a) a method b) an object c) a class d) a program

b) an object

Values that are sent into a method are called ________. a) variables b) arguments c) literals d) types

b) arguments

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. a) active array sequencing b) array bounds checking c) scope resolution binding d) buffer overrun protection

b) array bounds checking

The ________ indicates the number of elements the array can hold. a) new operator b) array's size declarator c) array's data type d) version of Java

b) array's size declarator

Methods are commonly used to ________. a) speed up the compilation of a program b) break a program down into small manageable pieces c) emphasize certain parts of the logic d) document the program

b) break a program down into small manageable pieces

Which of the following expressions determines whether the char variable, chrA, is not equal to the letter 'A'? a) chrA == 'A' b) chrA != 'A' c) chrA || 'A' d) chrA.notEquals(A)

b) chrA != 'A'

A(n) ________ can be thought of as a blueprint that can be used to create a type of ________. a) object, class b) class, object c) cookie, cake d) object, method

b) class, object

When an argument value is passed to a method, the receiving parameter variable is ________. a) declared within the body of the method b) declared in the method header inside the parentheses c) declared in the call d) used in the declaration of the argument

b) declared in the method header inside the parentheses

An item that separates other items is known as a ________. a) partition b) delimiter c) sentinel d) terminator

b) delimiter

A ________ is a boolean variable that signals when some condition exists in the program. a) sentinel b) flag c) block d) case

b) flag

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

b) has the same name as the class

In Java, you do not use the new operator when you use a(n) ________. a) array size declarator b) initialization list c) two-dimensional array d) any of these

b) initialization list

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 legal call to the displayValue method? a) int x = 7; void displayValue(x); b) int x = 7; displayValue(x); c) int x = 7; displayValue(int x); d) int x = 7; displayValue(x)

b) int x = 7; displayValue(x);

Which of the following is the not equal operator? a) NOT b) *& c) !=

c) !=

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000? a) ((x >= 500 && x <= 650) && (y != 1000)) b) ((x > 500 AND x < 650) OR !(y.equal(1000))) c) ((x > 500 && x < 650) || (y != 1000)) d) ((x < 500 && x > 650) || !(y == 1000))

c) ((x > 500 && x < 650) || (y != 1000))

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[]? a) 1 through 15 b) 1 through 14 c) 0 through 14 d) 0 through 15

c) 0 through 14

What will be printed when the following code is executed? double x = 45678.259; System.out.printf("%,.2f", x); a) 45678.259 b) 0,045,678.26 c) 45,678.26 d) 45,678.3

c) 45,678.26

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

c) 5.0

When writing documentation comments for a method, you can provide a description of each parameter by using a ________. a) @comment tag b) @doc tag c) @param tag d) @return tag

c) @param tag

Java was developed by ________. a) Microsoft b) IBM c) Sun Microsystems d) Hewlett-Packard

c) Sun Microsystems

Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9]; a) The numbers array has 54 rows. b) The numbers array has 15 rows. c) The numbers array has 6 rows and 9 columns. d) The numbers array has 6 columns and 9 rows.

c) The numbers array has 6 rows and 9 columns.

A computer program is ________. a) the same as main memory b) only used for desktop computers c) a set of instructions that allow the computer to solve a problem or perform a task d) another name for an operating system

c) a set of instructions that allow the computer to solve a problem or perform a task

The following statement is an example of ________. import java.util.*; a) an explicit import statement b) an unconditional import statement c) a wildcard import statement d) a conditional import statement

c) a wildcard import statement

If you prematurely terminate an if statement with a semicolon, the compiler will ________. a) not display an error message b) assume you are placing a null statement there c) both not display an error message and assume you are placing a null statement there d) none of these

c) both not display an error message and assume you are placing a null statement there

A class's responsibilities include ________. a) the things a class is responsible for knowing b) the things a class is responsible for doing c) both of these d) neither of these

c) both of these

A loop that executes as long as a particular condition exists is called a(n) ________ loop. a) infinite b) count-controlled c) conditional d) relational

c) conditional

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

c) data hiding

Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by ________. a) using the public access specifier on the class methods b) using the private access specifier on the class methods c) using the private access specifier on the class fields d) using the private access specifier on the class definition

c) using the private access specifier on the class fields

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

c) x = (float)y;

If x has been declared an int, which of the following statements is invalid? a) x = 0; b) x = -59832; c) x = 1,000; d) x = 592

c) x = 1,000;

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 = 160, y = 80 b) x = 32, y = 4 c) x = 37, y = 5 d) x = 9, y = 52

c) x = 37, y = 5

Which of the following is not one of the major components of a typical computer system? a) the CPU b) input/output devices c) main memory d) secondary storage devices e) All of these are major components

e) All of these are major components


Conjuntos de estudio relacionados

Chapter 5 The Integumentary System

View Set

Chapter 6 Resistance exercise for impaired muscle resistance

View Set