Java -Gaddis- Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which symbol indicates that a member is private a UML diagram?

-

Subscripting always starts with ________.

0

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[]?

0 through 14

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0;

0.0

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

12

What will be displayed after the following statements are executed? ins ans = 10; int x = 55; int y = 65; if (x >= y) { ans = x + y; } System.out.println(ans);

120

What will be the value of x after the following code is executed? int x, y = 15; x = y--;

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;

15

The no-arg constructor for a StringBuilder object gives the object enough storage space to hold ________ characters.

16

In the following code, assume that inputFile references a Scanner object that has been successfully used to open a file: double totalIncome = 0.0; while (inputFile.hasNext()) { try { totalIncome += inputFile.nextDouble(); }catch(InputMismatchException e) { System.out.println("Non-numeric data encountered " +"in the file.") ;inputFile.nextLine(); } finally { totalIncome = 35.5; } } What will be the value of totalIncome after the following values are read from the file?

35.5

What is the value of z after the following code is executed? int x = 5, y = 28; float z; z = (float) (y / x);

5.0

Given the following code, what will be the value of finalAmount when it is displayed? public class Order{private int orderNum;private double orderAmount;private double orderDiscount;public Order(int orderNumber, double orderAmt,double orderDisc){orderNum = orderNumber;orderAmount = orderAmt;orderDiscount = orderDisc;}public double finalOrderTotal(){return orderAmount - orderAmount *orderDiscount;}}public class CustomerOrder{public static void main(String[] args){Order order;int orderNumber = 1234;double orderAmt = 580.00;double orderDisc = .1;order = new Order(orderNumber, orderAmt, orderDisc);double finalAmount = order.finalOrderTotal();System.out.printf("Final order amount = $%,.2f\n",finalAmount);}}

522.00

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y / x);

8.0

What is the value of scores[2][3] in the following array?

94

________ tells the Java compiler that a method is meant to override a method in the superclass.

@Override

The StringBuilder class's insert method allows you to insert a(n) ________ into the calling object's string.

All of these

Which of the following is not part of the programming process?

All of these are parts of the programming process

________ is the term for the relationship created by object aggregation.

"Has a"

Protected class members can be denoted in a UML diagram with the ________ symbol.

#

Select all that apply. Which of the following are constructors of the BorderPane class?

BorderPane(center) BorderPane(center, top, right, bottom, left) BorderPane()

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

ClassA

Which of the following would contain the translated Java byte code for a program named Demo?

Demo.class

All of the exceptions that you will handle are instances of classes that extend the ________ class.

Exception

An array can hold multiple values of several different types of data simultaneously.

False

Both character and string literals can be assigned to a char variable.

False

If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is returned.

False

Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.

False

Only constants and variables may be passed as arguments to methods.

False

The public access specifier for a field indicates that the field may not be accessed by statements outside the class.

False

The throws clause causes an exception to be thrown.

False

When testing for character values, the switch statement does not test for the case of the character.

False

To read data from a binary file, you create objects from which of the following classes?

FileInputStream and DataInputStream

To write data to a binary file, you create objects from which of the following classes?

FileOutputStream and DataOutputStream

If you want to append data to an existing binary file, BinaryFile.dat, which of the following statements would you use to open the file?

FileOutputStream fstream = new FileOutputStream("BinaryFile.dat", true); DataOutputStream binaryOutputFile = new DataOutputStream(fstream);

If you want to append data to an existing binary file, BinaryFile.dat, which of the following statements would you use to open the file?

FileOutputStream fstream =new FileOutputStream("BinaryFile.dat", true);DataOutputStream binaryOutputFile =new DataOutputStream(fstream);

In Windows, which of the following statements will open the file, InputFile.txt, that is in the root directory on the C: drive?

FileReader freader = new FileReader("C:\\InputFile.txt");

Which of the following is not a rule that must be followed when naming identifiers?

Identifiers can contain spaces.

In the following code, which line in ClassA has an error? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodA(double) { } Line 10 }

Line 8

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)

Nothing. There is an error in the code.

The numeric classes' parse methods all throw an exception of ________ type if the string being converted does not contain a convertible numeric value.

NumberFormatException

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

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

The catch clause ________.

The catch clause does all of these

Given the following, which of the statements below is not true?str.insert(8, 32);

The insert will start at position 32.

What happens if a program does not handle an unchecked exception?

The program is halted and the default exception handler handles the exception.

When the code in a try block may throw more than one type of exception, you need to write a catch clause for each type of exception that could potentially be thrown.

True

When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

True

When working with the String and StringBuilder classes' getChars method, the character at the start position is included in the substring but the character at the end position is not included.

True

When you pass the name of a file to the PrintWriter constructor and the file already exists, it will be erased and a new empty file with the same name will be created.

True

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

ans = 60, x = 0, y = 50

Values stored in local variables ________.

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

All fields declared in an interface ________.

are treated as final and static

Values that are sent into a method are called ________.

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.

array bounds checking

A constructor ________.

has the same name as the class

When you write a method that throws a checked exception, you must ________

have a throws clause in the method header

Overloading means that multiple methods in the same class ________.

have the same name but different parameter lists

Select all that apply. Any method that calls a method with a throws clause in its header must ________.

have the same throws clause handle the potential exception

When working with the PrintWriter class, which of the following import statements should you have near the top of your program?

import java.io.*;

Methods that operate on an object's fields are called ________.

instance methods

Which of the following statements converts a String object variable named str to an int and stores the value in the variable x?

int x = Integer.parseInt(str)

Which of the following is a valid declaration for a ragged array with five rows but no columns?

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

Each repetition of a loop is known as a(n) ________.

iteration

Which of the following will run the compiled program called ReadIt?

java ReadIt

The ________ package is automatically imported into all Java programs.

java.lang

To compile a program named First you would use which of the following commands?

javac First.java

To return an array of long values from a method, which return type should be used for the method?

long[]

Each different type of CPU has its own ________.

machine language

A cross between human language and a programming language is called ________.

pseudocode

One type of design tool used by programmers when creating a model of a program is ________.

pseudocode

Byte code instructions are ________.

read and interpreted by the JVM

The ________ method removes an item from an ArrayList at a specific index.

remove

Character literals are enclosed in ________ and string literals are enclosed in ________.

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?

str1.equalsIgnoreCase(str2)

When using the throw statement, if you don't pass a message to the exception object's constructor, then ________.

the exception will have a null message

An object typically hides its data but allows outside code access to ________.

the methods that operate on the data

What is syntax?

the rules that must be followed when writing a program

The ________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted.

trim

An expression tested by an if statement must evaluate to ________.

true or false

The ________ loop allows the user to decide on the number of iterations.

user controlled loop

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

Which of the following are pre-test loops?

while, for

If object1 and object2 are objects of the same class, to make object2 a copy of object1 ________.

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

What would be the result after the following code is executed? int [ ] x = {23, 55, 83, 19}; int [ ] y = {36, 78, 12, 24}; for (int a = 0; a < x.length; a++) { x [a] = y[a]; y [a] = x[a]; }

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

In a multi-catch (introduced in Java 7) the exception types are separated in the catch clause by the ________ symbol.

|

If the expression on the left side of the && operator is false, the expression on the right side will not be checked.

True

Layout containers provide methods for fine-tuning the way controls are arranged.

True

Objects in an array are accessed with subscripts, just like any other data type in an array.

True

The System.out.printf method formats a string and displays it in the console window.

True

When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.

True

Which of the following is true about protected access?

Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package.

Which of the following statements will convert the double variable, d = 543.98 to a string?

String str = Double.toString(d);

To print "Hello, world" on the monitor, which of the following Java statements should be used?

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

Which of the following statements will display the maximum value that a double can hold?

System.out.println(Double.MAX_VALUE);

A class's static methods do not operate on the fields that belong to any instance of the class.

True

A variable's scope is the part of the program that has access to that variable.

True

An abstract class is not instantiated itself but serves as a superclass for other classes.

True

An enumerated data type is actually a special type of class.

True

An instance of a class does not have to exist in order for values to be stored in a class's static fields.

True

To serialize an object and write it to the file, use the ________ method of the ObjectOutputStream class.

WriteObject

When a method tests an argument and returns a true or false value, it should return ________.

a boolean value

If the this variable is used to call a constructor, ________.

a compiler error will result if it is not the first statement of the constructor

When a method's return type is a class, what is actually returned to the calling program?

a reference to an object of that class

A computer program is ________.

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

In the following code, System.out.println(num) is an example of ________. double num = 5.4; System.out.println(num); num = 0.0;

a void method

A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass.

abstract

When a subclass overloads a superclass method ________.

both methods may be called with a subclass object

If you prematurely terminate an if statement with a semicolon, the compiler will ________.

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

Methods are commonly used to ________.

break a program down into small manageable pieces

To create a method, you must write its ________.

definition

An item that separates other items is known as a ________.

delimiter

Given the following method header, which of these method calls is incorrect? public void displayValue(double x, int y);

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

Given the following method header, which of these method calls is incorrect? public void displayValue(int x, int y);

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.

do-while

If the code in a method can potentially throw a checked exception, then that method must ________.

either of these

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

false

If you have defined a class, SavingsAccount, with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts?

numAccounts = SavingsAccount.numberOfAccounts;

A(n) ________ is a software entity that contains data and procedures.

object

You cannot use the == operator to compare the contents of ________.

objects

When you work with a ________, you are using a storage location that holds a piece of data.

primitive variable


Set pelajaran terkait

(G) Give the meaning of the following PREFIXES

View Set

The Enlightenment in England (Modern Humanities)

View Set

Principals of Management study #2

View Set

Cell membrane Controls what comes into and out of a cell

View Set

Chapter 22: Management of Patients with Upper Respiratory Tract Disorders

View Set