Test #1 Review: Chapters 1-6

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

T or F: A file must always be opened before using it and closed when the program is finished using it.

True

T or F: A local variable's scope always ends at the closing brace of the block of code in which it is declared.

True

T or F: A method that stores a value in a class's field or in some other way changed the value of a field is known as a mutator method.

True

T or F: An access specifier indicates how the class may be accessed.

True

T or F: When you open a file with the PrintWriter class, the class can potentially throw an IOException.

True

Data hiding, which means that critical data stored inside the object is protected from code outside the object is accomplished in Java by:

Using the private access specifier on the class fields

What will be the value of ans after the following code has been executed? int ans = 10; int x = 65; int y = 55; if (x >= y) int ans = x + y;

120

What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x = x - y;

15

Which of the following will format 12.78 to display as 012.8? A. 000.0 B. #0.00 C. ###.# D. ##0.0%

A. 000.0

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

When an object is created, the fields associated with the object are called: A. Instance fields B. Instance methods C. Fixed fields D. Class instances

A. Instance fields

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. Values may not be passed to methods D. The method must not assign another value to the parameter that receives the argument

A. Its value is copied into the method's parameter variable

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 C. Inside the parentheses of a method header D. The method in which they are defined

A. The instance methods of the same class

This 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

T or F: A method that gets a value from a class's field but does not change it is known as a mutator method.

False

T or F: Both character literals and string literals can be assigned to a char variable.

False

T or F: In Java the variable named One is the same as the variable named ONE

False

T or F: When testing for character values, the switch statement does not test for the case of the character.

False

What will be displayed as a result of executing the following code? int x = 8; String msg = "I am enjoying java."; String msg1 = msg.toUpperCase(); String msg2 = msg.toLowerCase(); char ltr = msg.charAt(x); int strSize = msg.length(); System.out.println(msg); System.out.println(msg1); System.out.println(msg2); System.out.println("Character at index x = " + ltr); System.out.println("msg has " + strSize + " characters.");

I am enjoying java. I AM ENJOYING JAVA. i am enjoying java. Character at index x = o msg has 19 characters.

What will be printed when the following code is executed? int y = 10; if ( y == 10) { int x = 30; x += y; } System.out.print("x = "); System.out.print(x);

x is unknown when the last statement is executed

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; }

0.0

What will be the value of x after the following code is executed? int x = 10; do { x *= 20; } while (x < 5); A. 10 B. 200 C. This is an infinite loop D. This loop will not be executed, the initial value of x > 5

B. 200

In the Programming Process which of the following is not involved in defining what the program is to do? A. Process B. Compile code C. Input D. Output E. Purpose

B. Compile code

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 calling method D. Uses the declaration of the argument

B. Declared in the method header inside the parentheses

Before entering a loop to compute a running total, the program should first: A. Read all the values into main memory B. Set the accumulator where the total will be kept to an initial value, usually zero C. Know exactly how many values there are to total D. Set all variables to zero

B. Set the accumulator where the total will be kept to an initial value, usually zero

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);

After the header, the body of the method appears inside a set of: A. Brackets, [ ] B. Parentheses, ( ) C. Braces, { } D. Double qoutes, " "

C. Braces, { }

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens? A. Control is returned to method A B. Control is returned to method B C. Control is returned to method C D. The program terminates

C. Control is returned to method C

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

A constructor: A. Always accepts two arguments B. Has return type of void C. Has the same name as the class D. Always has an access specifier of private

C. Has the same name as the class

This part of a method is 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

Which of the following does not describe a valid comment in Java? A. Single line comments, two forward slashes - // B. Multi-line comments, start with /* and end with */ C. Multi-line comments, start with */ and end with /* D. Documentation comments, any comments starting with /**

C. Multi-line comments, start with */ and end with /*

Which of the following is always included in a method call? A. Return type B. Method modifiers C. Parentheses D. Return variable

C. Parentheses

To document the return value of a method, use this in a documentation comment. A. The @param tag B. The @comment tag C. The @return tag D. The @returnValue tag

C. The @return tag

This type of loop is ideal in situations where the exact number of iterations is known. A. while loop B. do-while loop C. for loop D. if statement

C. for loop

A flag may have the values: A. 0 and 1 B. +1 and -1 C. true or false D. Of any character

C. true or false

Which of the following is not a benefit derived from using methods in programming? A. Problems are more easily solved B. Simplifies programs C. Code reuse D. All of these are benefits

D. All of these are benefits

This is an item that separates other items. A. Separator B. Partition C. Doorway D. Delimeter

D. Delimiter

What is the value of ans after the following code has been executed? int x = 40; int y = 40; int ans = 0; if (x = y) ans = x + 10; A. 50 B. 80 C. 30 D. No value, this is a syntax error

D. No value, this is a syntax error

In the following code, what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner (System.in); System.out.print("Enter a number: "); int number = keyboard.nextInt( ); while (number < 100 || number > 500) { System.out.print("Enter another number: "); number = keyboard.nextInt( ); } A. Numbers less than 100 B. Numbers greater than 500 C. Numbers in the range 99 through 501 D. Numbers in the range 100 through 500

D. Numbers in the range 100 through 500

This is a value that signals when the end of a list of values has been reached. A. Terminal value B. Final value C. End value D. Sentinel

D. Sentinel

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

What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x += y; } A. 90 B. 110 C. 210 D. This is an infinite loop

D. This is an infinite loop

What will be the value of x after the following code is executed? int x = 10; while (x < 100); { x += 10; } A. 90 B. 100 C. 110 D. This is an infinite loop

D. This is an infinite loop

Which Scanner class method reads a String? A. readString ( ) B. nextString ( ) C. getString ( ) D. nextLine

D. nextLine

A byte is a collection of:

Eight bits

Suppose you are at an operating system command line, and you are going to use the following command to compile a program: javac MyClass.java Before entering the command, you must:

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

What is syntax?

Rules that must be followed when writing a program

Application software refers to:

The programs that make the computer useful to the user

In an if/else statement, if the boolean expression is false,

The statement or block following the else is executed


Kaugnay na mga set ng pag-aaral

Histology 111 (Cardiovascular System)

View Set

US History: Q3 - Quiz 1 - Assignment 3_Quiz: Reconstruction

View Set

Leadership: Chapter 3, 5 & 13 Review

View Set

chapter 60: introduction to the musculoskeletal system adult concepts

View Set

FInalized Social Psychology quizlet for quiz and test 1

View Set