Java Final Multiple Choice

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

_____ occurs when an instance of a class is a field in another class. class fielding Static Transferance Instantiation Aggregation

Aggregation

Every class must have at least one constructor in addition to the default constructor. True False

False

What type of exceptions are PrintWriter objects capable of throwing? FileException IOException WriterException TypeException

IOException

What does the following code do? int number = 5; number++; decrements number by 1 Increments number by 1 increments number by 2 decrements number by 2

Increments number by 1

The three sections of a for loop are: Initialization; Test; Update Update; Initialization; Test Test; Initialization; Update Condition; Test; Increment

Initialization; Test; Update

What will be displayed after executing the following code? public class Test { public static void main(String[] args) { int value1 = 9; System.out.printf(value1); int value2 = 45; System.out.printf(value2); System.out.printf(value3); value3 = 16;} } 94516 94516 9 45 16 Nothing, this code contains logic errors. Nothing, this code contains syntax errors.

Nothing, this code contains syntax errors.

What is displayed after executing the following code? int x = 578; System.out.printf("%nThere are " + "%d5%n" + "hens in the hen house."); There are x5\nhens in the hen house. There are 583 hens in the hen house. There are 5785 hens in the hen house. Nothing. There is an error in the code.

Nothing. There is an error in the code.

What type of loop is a While loop? Infinite Postest Pretest Boolean

Pretest

What two classes can you use to write data to a file. FileWriter and File PrintWriter and Scanner Scanner and File PrintWriter and FileWriter

PrintWriter and FileWriter

What class provides several methods for searching and working with String objects? isString String SubString Symbols

String

T/F? A method can return a reference to an object? True False

T

Suppose you have declared and initialized a String named lastName and that a Scanner object named input will be used capture user input. What is wrong with the following code? Scanner input = System.in; System.out.printf("%nPlease enter your last name: "); lastName = input.nextLine(); The Scanner object is not declared as a new object. The println method should be used instead of printf. The nextLine variable does not need parentheses. The input variable should call atLine().

The Scanner object is not declared as a new object.

A do-while loop always performs at least one iteration, even if the Boolean expression is false to begin with. True False

True

An import declaration is not required when one class in a package uses another in the same package. True False

True

Is the following code snippet valid in Java? int a = 4; int b = 5; if(a > b) System.out.println("a is greater than b"); else System.out.println("b is greater than a"); True False

True

Java maintains only one copy of each method of a class in memory. True False

True

The while repetition structure will continue to execute its statement block as long as the Boolean expression of the header is: less than the pre-condition null False True

True

Which of the following is the correct syntax for the NOT logical operator? (!condition) NOT not !(condition)

!(condition)

Which of the following is the correct syntax for the AND logical operator. AND & && and

&&

What is the first negative index in a string? 0 -1 -0 the size of the string minus one

-1

A Javadoc comment begins with _______. */ /* /** //**

/**

A single line Java comment begins with _______. * */ /* //

//

Java automatically stores what value in all uninitialized static member variables? undefined null 0 1

0

In a declaration statement, what symbols indicate an array? {} [] () <>

[]

Any stand-alone class, for example, Scanner, can be used by any other stand-alone class or _______ class. application main Java Scanner

application

A method may be written so that it accepts ____. parameters values data arguments

arguments

A combined assignment operator consists of a(n) _______ operator and the assignment operator. unary arithmetic ternary integral

arithmetic

An enhanced for loop _______. uses a counter stores values in an array reassigns the array reference variable avoids array-out-of-bounds errors

avoids array-out-of-bounds errors

Which of the following is the correct syntax for boolean variables: boolean a = TRUE; boolean b = FALSE; boolean a = True; boolean b = False; boolean a = true; boolean b = false; a = true; b = false;

boolean a = true; boolean b = false;

The switch statement evaluates its expression, then executes all statements that follow the matching ____ labels. default break condition case

case

A program with a header containing the program's name is a(n) _______. class identifier method variable

class

Computers process data under the control of sequences of instructions called _______. hardware Moore's law logical units computer programs

computer programs

The ______ section of a switch block handles all values that are not explicitly handled by one of the case sections. case default break continue

default

Complete the following block of code: int time = 22; if (time < 10) { System.out.println("Good morning."); } /*what goes here*/ (time < 18) { System.out.println("Good day."); } else { System.out.println("Good evening."); } else if if (test case here) else if else

else if

What condition do we use to specify a new condition to test, if the first condition is false? if else else if elif else else

else if

You can use the ____ key word to create your own data type and specify the values that belong to that type. For instance: ____ Cars {FORD, CHEVY, TOTYOTA, BMW} unique define structure enum

enum

The indexOf() method searches the calling String object for the character passed into ch. If the character is found, the position of its ____occurrence is returned. Otherwise, ___ is returned. first, -1 last, 0 first, 1 last, -1

first, -1

Which loop header in the average method's body would best handle displaying the values of the parameter numbers? public static double average(double... numbers) for(int i = 1; i < size; i++) while(index <= size) for(int i = 0; i <= numbers.length; i++) for(double d : numbers)

for(double d : numbers)

The Java Virtual Machine periodically performs this process, which automatically removes unreferenced objects from memory? garbage collection memory cleansing object expungement memory deallocation

garbage collection

Class names, method names, and variable names are all _______. headers reserved key words identifiers

identifiers

If the value of an expression can be determined based on the left operand alone, the right operand is not evaluated at all. The term that describes this concept is called _________? left-evaluation short-circuit quick-circuit binary-evaluation

short-circuit

The term _______ typically refers to the device that displays console output. liquid crystal display standard output device central processing unit secondary storage device

standard output device

A ____ class member belongs to the class, not objects instantiated from the class. void static public private

static

This type of method cannot access any non-static member variables in its own class. instance void non-static static

static

The term _____ is commonly used to refer to a string that is part of another string subwrapper subtext innerstring substring

substring

If an array is declared at the class level, _______. the array must also be created at the class level for the class methods to use it the array is available to some of the class methods but not all the size of the array is determined at the class level the array is created at the method level when the size is determined

the array is created at the method level when the size is determined

Given the following code, what is passed to the method modifyArray? double[] hourlyTemperatures = new double[24]; modifyArray(hourlyTemperatures); a copy of the array hourlyTemperatures a copy of the first element of the array hourlyTemperatures the address of each element in array hourlyTemperatures the reference to or address of array hourlyTemperatures

the reference to or address of array hourlyTemperatures

The most efficient way to code for initialization of instance variables and perform additional processing on them is through _________________________________. repeat code in multiple constructors the use multiple instance variable initializers class code without any constructors the use of an instance initializer

the use of an instance initializer

Consider the following statements: double elementFromArray = 0.0; for(int i = 0; i < 5; i++) { elementFromArray = getArrayElement(i); System.out.printf(elementFromArray);} The method getArrayElement returns _______. the address of the array the index position of each element the size of the array the value stored in a specified index location

the value stored in a specified index location

The ____ key word is the name of a reference variable that an object can use to refer to itself. static self this same

this

This method returns a string representing the state of the object. plusString() getString() toString() ordinal

toString()

This method returns a copy of the calling String object, in which all leading and trailing whitespace character have been deleted. remove() strip() trim() deleteWhiteSpaces()

trim()

The expression tested by an if statement must evaluate to _______. 0 or 1 +1 or -1 Numerical or boolean results are possible. true or false

true or false

A __ method simply executes a group of statements and then terminates. value-returning void final unified

void

The parse() methods are a type of ____ _____ wrapper class primitive variables constructor methods constructor class

wrapper class

Which statement could be rewritten using a combined assignment operator? num1 = num2 + num3; x = x % y; value1 = value2 * value3 * value4; total = grandTotal - total;

x = x % y;

Which of the following is the correct operator for the OR logical operator? || | // OR

||

Given the code snippet below, what value will number be when the for loop finishes executing all iterations? int number ; for (number = 5; number <=15; number++) { System.out.println(number); } 4 14 15 5

15

What will be the result of the following code snippet? int number = 4; System.out.println(++number); 6 4 5 8

5

Since an array has only one name, _______ provides access to each data element. a counter an accumulator a length field an index

an index

Which of the following is the correct output for the following block of code? public class WrapperClasses { public static void main(String[] args){ char [] values = {'a', 'q', '2', 's', '8'}; System.out.println(String.valueOf(values, 1, 2)); } } q2s8 q2 2s aq2s8 q 2

q2

Which common method of class ArrayList<T> is overloaded? get clear contains remove

remove

When an array index is re-assigned, the original array's elements are _______. duplicated deleted inaccessible replaced

inaccessible

Which of the following methods returns true if the argument passed into ch is an alphabetic letter? Ex.boolean ______(char ch) isDigit isAlpha isLetter isNotDigit

isLetter

Which of the following methods returns true if the argument passed into ch contains a digit (0 through 9) or an alphabetic character? Ex.boolean ______(char ch) isLetterOnly isDigitOnly isAlphaNumeric isLetterOrDigit

isLetterOrDigit

The Character class is part of what java package? java.swing java.lang java.wrapper java.util

java.lang

What package is needed when writing code using the ArrayList class? java.util java.lang java.io java.net

java.util

What does the word static mean, with respect to methods in Java? Method can be seen by code outside the class method belongs to a specific object, not the class method belongs to the class, not a specific object method cannot be altered

method belongs to the class, not a specific object

When declaring a two-dimensional array with nested initializers, the number of nested sets of braces determines the _______. number of columns number of elements in each row number of rows total number of elements in the table

number of rows

A class allows other programs to use a class' code through _______. references objects methods arguments

objects

A wrapper class is a class that is "wrapped around" a primitive data type and allows you to create ____ instead of variables. methods attributes fields objects

objects

The do-while is what type of loop? posttest pretest innertest outertest

posttest

Java types are divided into _______. relational types and reference types logical types and relational types primitive types and reference types implicit types and explicit types

primitive types and reference types


Conjuntos de estudio relacionados

Overview of Animal Reproduction and Development

View Set

B-05 Part 1 - Define & Provide Examples of Schedules of Reinforcement

View Set

Ch. 30: Classical Dichotomy and Monetary Neutrality

View Set