Final Exam Java ITP 120 CH 6-11

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

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

"Has a"

The whole-part relationship created by object aggregation is more often called a(n) __________ relationship.

"has a"

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

-

By default, Java initializes array elements to __________.

0

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

The insert will start at position 32.

A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.

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

If you are using characters other than whitespaces as delimiters, you will probably want to trim the string before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last token.

True

The java.lang package is automatically imported into all Java programs.

True

The term "no-arg constructor" is applied to any constructor that does not accept arguments.

True

When you deserialize an object using the readObject method, you must cast the return value to the desired class type.

True

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

WriteObject

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

The __________ indicates the number of elements the array can hold.

array's size declarator

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

ClassC

__________ refers to combining data and code into a single object.

Encapsulation

Unchecked exceptions are those that inherit from the __________.

Error class or the RuntimeException class

If a string has more than one character used as a delimiter, you must write a loop to determine the tokens, one for each delimiter character.

False

If a[] and b[] are two integer arrays, the expression a == b compares the array contents.

False

The names of the enum constants in an enumerated data type must be enclosed in quotation marks.

False

When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.

False

What does the following statement do? double[] array1 = new double[10];

It does all of these.

When an individual element of an array is passed to a method __________.

the method does not have access to the original array

It is common practice in object-oriented programming to make all of a class's __________.

fields private

When a method is declared with the __________ modifier, it cannot be overridden in a subclass.

final

The try statement may have an optional __________ clause which must appear after all of the catch clauses.

finally

If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?

for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }

The JVM periodically performs the __________ process to remove unreferenced objects from memory.

garbage collection

Overloading means that multiple methods in the same class __________.

have the same name but different parameter lists

In Java, you do not use the new operator when you use a(n) ____________.

initialization list

A class that is defined inside another class is called a(n) __________.

inner class

Another term for an object of a class is a(n) __________.

instance

When an object is created, the attributes associated with the object are called __________.

instance fields

A search algorithm __________.

is used to locate a specific item in a collection of data

When the this variable is used to call a constructor__________.

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

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

long[]

A reference variable stores a(n) __________.

memory address

Replacing inadequate superclass methods with more suitable subclass methods is known as __________.

method overriding

A subclass can directly access __________.

only public and protected members of the superclass

If two methods have the same name but different signatures they are __________.

overloaded

If a method in a subclass has the same signature as a method in the superclass, the subclass method __________ the superclass method.

overrides

A constructor is a method that __________.

performs initialization or setup operations

A subclass may call an overridden superclass method by __________.

prefixing its name with the super key word and a dot (.)

Which of the following statements declares Salaried as a subclass of PayType?

public class Salaried extends PayType

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passArray(int [][])

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

remove

A(n) __________ is used as an index to pinpoint a specific element within an array.

subscript

The term ________ commonly is used to refer to a string that is part of another string.

substring

The term __________ is commonly used to refer to a string that is part of another string.

substring

The scope of a private instance field is __________.

the instance methods of the same class

If a class contains an abstract method __________.

the method will only have a header, but not a body, and will end with a semicolon

If you attempt to perform an operation with a null reference variable __________.

the program will terminate

In an inheritance relationship __________.

the superclass constructor always executes before the subclass constructor

The process of converting a wrapper class object to a primitive type is known as __________.

unboxing

In Java there are two categories of exceptions which are __________.

unchecked and checked

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 would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a < array1.length; a++) { value += array1[a]; }

value contains the sum of all the values in array1.

The "has a" relationship is sometimes called a(n) __________ because one object is part of a greater whole.

whole-part relationship

When you make a copy of the aggregate object and of the objects that it references, __________.

you are performing a deep copy

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

|

What will be the result of the following statements? FileOutputStream fstream = new FileOutputStream("Output.dat"); DataOutputStream outputFile = new DataOutputStream(fstream);

The outputFile variable will reference an object that is able to write binary data to the Output.dat file.

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

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

When an exception is thrown __________.

it must be handled by the program or by the default exception handler

__________ is a special type of expression used to create an object that implements a functional interface.

lambda

Instance methods do not have the __________ key word in their headers

static

When a reference variable is passed as an argument to a method __________.

the method has access to the object that the variable references

All exceptions are instances of classes that extend the __________ class.

Throwable

Each of the numeric wrapper classes has a static ________ method that converts a number to a string.

ToString

You can change the contents of a StringBuilder object, but you cannot change the contents of a String object.

True

You cannot use the fully-qualified name of an enum constant for ___________.

a case expression

A file that contains raw binary data is known as a __________.

machine file

A(n) __________ contains one or more statements that are executed and can potentially throw an exception

try block

In the following code, which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public final int method2(double b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b){} Line 11 public int method2(double c){} Line 12 }

Line 11

The following catch statement can __________. catch (Exception e) {...}

handle all exceptions that are instances of the Exception class or one of its subclasses

When you write a method that throws a checked exception, you must __________.

have a throws clause in the method header

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

instance methods

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

False

Which of the following is an example of a lambda expression?

IntCalculator multiplier = x -> x * factor;

When an object is serialized, it is converted into a series of bytes that contain the object's data

True

You can concatenate String objects by using the __________.

concat method or the + operator

In a catch statement, what does the following code do? System.out.println(e.getMessage());

It prints the error message for an exception.

Which of the following statements will print the maximum value an int variable may have?

System.out.println(Integer.MAX_VALUE);

An ArrayList object automatically expands in size to accommodate the items stored in it.

True

Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.

True

The wrapper classes in Java are immutable, which means that once you create an object, you cannot change the object's value.

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

The following statement is an example of __________. import java.util.*;

a wildcard import statement

Which of the following statements will convert the string, str = "285" to an int?

int x = Integer.parseInt(str);

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

jumped

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

trim

What will the following code display? String input = "99#7"; int number; try { number = Integer.parseInt(input); } catch(NumberFormatException ex) { number = 0; } catch(RuntimeException ex) { number = 1; } catch(Exception ex) { number = -1; } System.out.println(number);

0

Instance methods should be declared static.

False

Enumerated types have the __________ method which returns the position of an enum constant in the declaration list.

ordinal

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

A protected member of a class may be directly accessed by __________.

Any of these

Which of the following is not true about static methods?

They are called from an instance of the class.

A class becomes abstract when you place the __________ key word in the class definition.

abstract

The term used for the character that separates tokens is __________.

delimiter

Given the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method1 will be executed when the following statements are executed? ClassA item1 = new ClassB(); item1.method1();

method1 on Line 9

A declaration for an enumerated type begins with the __________ key word.

enum

What will be displayed after the following statements are executed? String str = "red$green&blue#orange"; String[] tokens = str.split("[$&#]"); for (String s : tokens) System.out.print(s + " ");

red green blue orange

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

#

What will be the result of the following statements? FileInputStream fstream = new FileInputStream("Input.dat"); DataInputStream inFile = new DataInputStream(fstream);

The inFile variable will reference an object that is able to read binary data from the Input.dat file.

If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

numbers[r].length

A group of related classes is called a(n) __________.

package

Which of the following import statements is required to use the Character wrapper class?

No import statement is required

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

NumberFormatException

Which of the following is true about protected access?

Protected members may be accessed by methods in the same package or in a subclass, but only if the subclass is in the same package.

Which of the following statements will create a reference, str, to the String "Hello, World"?

String str = "Hello, World";

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 two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9];

The numbers array has 6 rows and 9 columns.

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

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

Declaring an array reference variable does not create an array.

True

In a try statement, the try clause must appear first, followed by all of the catch clauses, followed by the optional finally clause

True

Trying to extract more tokens than exist from a StringTokenizer object will cause an error.

True

When a subclass extends a superclass, the public members of the superclass become public members of the subclass.

True

What will be the results after the following code is executed? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8;

a = 5

What does the following UML diagram entry mean? + setHeight(h : double) : void

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

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

a reference to the String object containing "ghi"

When an array is passed to a method __________.

All of these are true

The throws clause causes an exception to be thrown.

False

When catching multiple exceptions that are related to one another through inheritance you should handle the more general exception classes before the more specialized exception classes.

False

In the following code, what is missing from ClassA? 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 methodB(double) { } Line 10 }

It does not overload methodA.

Which of the following is not true about static methods?

It is necessary for an instance of the class to be created to execute the method.

A constructor __________.

has the same name as the class

The ArrayList class is in the __________ package.

java.util

Class objects normally have __________ that perform useful operations on their data, but primitive variables do not.

methods

In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println("This is the last statement "+ "in the constructor."); } }

It will call the constructor of ClassA that receives an integer as an argument.

If a subclass constructor does not explicitly call a superclass constructor __________.

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

The __________ method of the String class can be used to tokenize a string.

split

An object's __________ is simply the data that is stored in the object's fields at any given moment.

state

In order to do a binary search on an array __________.

the array must first be sorted

The sequential search algorithm __________.

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

To compare two objects in a class, __________.

write an equals method that will make a field by field compare of the two objects

The __________ key word is used to call a superclass constructor explicitly.

super

In Java it is possible to write a method that will return __________.

Any of these

If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.

True

It is not possible for a superclass to call a subclass's method.

True

StringBuilder objects are not immutable.

True

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

W

What are the tokens in the following code? String str = "123-456-7890"; String[] tokens = str.split("-");

123, 456,7890

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

Any items typed on the command line, separated by a space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.

True

Because the subclass is more specialized than the superclass, it is sometimes necessary for the subclass to replace inadequate superclass methods with more suitable ones.

True

Every class has a toString method and an equals method inherited from the Object class.

True

If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector.

True

The String class's __________ method accepts a value of any primitive data type as its argument and returns a string representation of the value.

valueOf

The binary search algorithm __________.

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

An access specifier indicates how a class may be accessed.

True

Once an array is created, its size cannot be changed.

True

Static methods can only operate on __________ fields.

static

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.

str[0].toUpperCase();

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 type of relationship exists between two objects when one object is a specialized version of another object?

"is a"

Subscripting always starts with __________.

0

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

16

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

@Override

You can declare an enumerated data type inside a method.

False

What is required for an interface method that has a body?

The method header must begin with the key word default.

Most of the String comparison methods are case sensitive.

True

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

Which symbol indicates that a member is public in a UML diagram?

+

Java automatically stores a __________ value in all uninitialized static member variables.

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 position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.indexOf("ov");

15

What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};

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

The __________ class is the wrapper class for the char data type.

Character

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

Exception

All of the exceptions 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

If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.

False

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } }

The call to the method super must be the first statement in the constructor.

What would be the result after the following code is executed? int[] numbers = {40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; }

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

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

True

When an object is passed as an argument, it is actually a reference to the object that is passed.

True

When an object reference is passed to a method, the method may change the values in the object.

True

enum constants have a toString method.

True

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

The IllegalArgumentException class extends the RuntimeException class and is, therefore, __________.

an unchecked exception class

If your code does not handle an exception when it is thrown, __________ prints an error message and crashes the program.

default exception handler

What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17);

diddl

A(n) __________ is an object that is generated in memory as the result of an error or an unexpected event.

exception

A(n) __________ is a section of code that gracefully responds to exceptions when they are thrown.

exception handler

Which key word indicates that a class inherits from another class?

extends

If a random access file contains a stream of characters, which of the following statements would move the file pointer to the starting byte of the fifth character in the file?

file.seek(8);

An exception object's default error message can be retrieved using the __________ method.

getMessage

The __________ package is automatically imported into all Java programs.

java.lang

Each array in Java has a public field named __________ that contains the number of elements in the array.

length

When writing a string to a binary file or reading a string from a binary file, it is recommended that you use __________.

methods that use UTF-8 encoding

When using the String class's trim method, a __________ cannot be trimmed.

semicolon

You can use the __________ method to replace an item at a specific location in an ArrayList

set

The Character wrapper class provides numerous methods for __________.

testing and converting character data

Given the following method header, what will be returned from the method? public Rectangle getRectangle()

the address of an object of the Rectangle class

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}

What will be printed after the following code is executed? String str = "abc456"; int m = 0; while ( m < 6 ) { if (Character.isLetter(str.charAt(m))) System.out.print( Character.toUpperCase(str.charAt(m))); m++; }

ABC

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

All of these

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

What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>();

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

In versions of Java prior to Java 7 each catch clause could handle only one type of exception.

True

Instance methods do not have the key word static in their headers.

True

Java does not limit the number of dimensions an array may have.

True

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

True

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

True

The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.

True

The ability to catch multiple types of exceptions with a single catch clause is known as multi-catch and was introduced in Java 7

True

Which of the following is the operator used to determine whether an object is an instance of a particular class?

instanceOf

What is the value of scores[2][3] in the following array? int[][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };

94

Given the following code, which statement is true? public class ClassB implements ClassA{ }

ClassB must override each method in ClassA.

If two methods in the same class have the same name but different signatures, the second overrides the first.

False

In an inheritance relationship, the subclass constructor always executes before the superclass constructor.

False

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

False

Java limits the number of dimensions that an array can have to 15.

False

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 will be displayed after the following code is executed?

The cow jumped over the moon.

What would be the result after the following code is executed? int[] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for (int i = 1; i < numbers.length; i++) value += numbers[i];

The value variable will contain the sum of all the values in the numbers array.

A constructor is a method that is automatically called when an object is created.

True

A functional interface is simply an interface that has one abstract method.

True

To determine if two arrays are equal you must compare each of the elements of the two arrays.

True

When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object.

True

When an array of objects is declared but not initialized, the array values are set to null.

True

When an exception is thrown by a method that is executing under several layers of method calls, a stack trace indicates the method executing when an exception occurred and all of the methods that were called in order to execute that method.

True

An exception's default error message can be retrieved by using the __________ method.

getMessage()

You should not define a class that is dependent on the values of other class fields __________.

in order to avoid having stale data

Beginning with Java7, to catch multiple exceptions with a single catch, you can use __________.

multi-catch

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?

the code

A partially filled array is normally used __________.

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

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;

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

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? 2.5 8.5 3.0 5.5 abc 1.0

35.5

The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value.

False

The throw statement informs the compiler that a method throws one or more exceptions.

False

You cannot assign a value to a wrapper class object.

False

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

A class is not an object. It is a description of an object.

True

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

True

A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final.

True

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

True

A single copy of a class's static field is shared by all instances of the class.

True

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

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

Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created.

True

If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method.

True

If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.

True

If the class SerializedClass contains references to objects of other classes as fields, those classes must also implement the Serializable interface in order to be serialized.

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

You can write a super statement that calls a superclass constructor but only in the subclass's constructor.

True

If str is declared as: String str = "ABCDEFGHI"; What will be returned from the following statement? Character.toLowerCase(str.charAt(5))

f

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

In Java, a reference variable is __________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance.

polymorphic

All methods specified by an interface are __________.

public

What will be the results after the following code is executed? int[] array1 = new int[25]; ... // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; }

value contains the lowest value in array1

What will be displayed after the following code is executed? String str = "abc456"; for (int i = 0; i < str.length(); i++) { char chr = str.CharAt(i); if (!Character.isLetter(chr)) System.out.print(Character.toUpperCase(chr)); }

456

In order for an object to be serialized, its class must implement the __________ interface.

Serializable

Given the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method will be executed when the following statements are executed? ClassC item1 = new ClassA(); item1.method1();

This is an error and will cause the program to crash.

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

Tree.PINE

If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent: System.out.println(object1); System.out.println(object1.toString());

True

In __________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.

a UML diagram

A ragged array is __________.

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

Which of the following statements will convert the string, str = "285.74" to a double?

double x = Double.parseDouble(str);

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

either of these

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

objects

When a field is declared static there will be __________.

only one copy of the field in memory

A __________ member's access is somewhere between public and private.

protected

If you don't provide an access specifier for a class member, the class member is given __________ access by default.

protected

Which of the following statements correctly specifies two interfaces?

public class ClassA implements Interface1, Interface2

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passMyArray(int[][])

When an exception is thrown by code in its try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to __________.

the first catch clause that can handle the exception

The scope of a public instance field is __________.

the instance methods and methods outside the class

In a class hierarchy __________.

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

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

the object's memory address

In a try/catch construct, after the catch statement is executed __________.

the program resumes at the statement that immediately follows the try/catch construct

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

Given the following constructor code, which of the statements are true? public Book(String ISBNOfBook, double priceOfBook, int numberOrderedOfBook) { if (ISBNOfBook == "") throw new BlankISBN(); if (priceOfBook < 0) throw new NegativePrice(priceOfBook); if (numberedOrderedOfBook < 0) throw new NegativeNumberOrdered(numberOrderedv); ISBN = ISBNOfBook; price = priceOfBook; numberedOrdered = numberOrderedOfBook; }

All of these are true.

The following statement correctly creates a StringBuilder object. StringBuilder str = "Tuna sandwich";

False

The key word this is the name of a reference variable that is available to all static methods.

False

The term "default constructor" is applied to the first constructor written by the author of the class.

False

For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; }

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

For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; }

The z field is available to code written outside the Sphere class.

If the following is from the method section of a UML diagram, which of the statements below is true? + add(object2:Stock) : Stock

This is a public method named add that accepts and returns references to objects in the Stock class

If the following is from the method section of a UML diagram, which of the statements below is true? + equals(object2:Stock) : boolean

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

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

abstract

The RandomAccessFile class treats a file as a stream of __________.

bytes

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

It is common practice to use a __________ variable as a size declarator.

final

Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"};

for (int i = 0; i < names.length; i++) System.out.println(names[i].length());

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;

Most of the programming languages used today are __________.

object-oriented

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

primitive variable

When declaring class data members it is best to declare them as __________.

private members

What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; }

60

In the following code, how many times will the for loop execute? String str = ("Ben and Jerry's ice cream is great."); String[] tokens = str.split(" "); for (String s : tokens) System.out.println(s);

7

In the following code, how many times will the for loop execute? String str = "1,2,3,4,5,6,7,8,9"); String[] tokens = str.split(","); for (String s : tokens) System.out.println(s);

9

What are the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2018", "-", true);

9, 14, 2018

CRC stands for __________.

Class, Responsibilities, Collaborations

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

ClassA

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

ClassB

A catch clause that uses a parameter variable of the Exception type is capable of catching any exception that extends the Error class.

False

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

False

A sorting algorithm is used to locate a specific item in a larger collection of data.

False

All methods in an abstract class must also be declared abstract.

False

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 int getOrderAmount() { return orderAmount; } public int getOrderDisc() { return orderDisc; } } public class CustomerOrder { public static void main(String[] args) { int ordNum = 1234; double ordAmount = 580.00; double discountPer = .1; Order order; double finalAmount = order.getOrderAmount() — order.getOrderAmount() * order.getOrderDisc(); System.out.printf("Final order amount = $%,.2f\n", finalAmount); } }

There is no value because the object, order, has not been created.

What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; }

This code would cause the program to crash.

An object can store data.

True

The ___________ method is used to insert an item into an ArrayList.

add

Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?

add

A static field is created by placing the key word static __________.

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

The following statement is an example of __________. import java.util.Scanner;

an explicit import statement

When a subclass overloads a superclass method __________.

both methods may be called with a subclass object

A UML diagram does not contain __________.

the object names

To indicate the data type of a variable in a UML diagram, you enter __________.

the variable name followed by a colon and the data type

The only limitation that static methods have is __________.

they cannot refer to nonstatic members of the class

Two or more methods in a class may have the same name as long as __________.

they have different parameter lists

A series of words or other items of data, separated by spaces or other characters, is known as a __________.

token

The process of breaking a string down into tokens is known as __________.

tokenizing

The ________ character appears at the end (the right side) of a string, after the non-space characters.

trailing whitespace

What will be the value of matches after the following code is executed? boolean matches; String[] productCodes = {"456HI345", "3456hj"}; matches = productCodes[0].regionMatches(true, 1, productCodes[1], 2, 3);

true

If a subclass constructor does not explicitly call a superclass constructor, __________.

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

Java allows you to create objects of the __________ class in the same way you would create primitive variables.

String

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

String str = Double.toString(d);

The String class's regionMatches method performs a case-insensitive comparison.

True

The call stack is an internal list of all the methods that are currently executing.

True

What will be displayed after the following statements are executed? StringBuilder strb = new StringBuilder("We have lived in Chicago, Trenton, and Atlanta."); strb.replace(17, 24, "Tampa"); System.out.println(strb);

We have lived in Tampa, Trenton, and Atlanta.

If ClassC is derived from ClassB which is derived from ClassA, this would be an example of

a chain of inheritance

If a method does not handle a possible checked exception, what must the method have?

a throws clause in its header

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.lastIndexOf("ov", 14);

-1

Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the ordinal value of the MAPLE enum constant?

1

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

False

Autoboxing is __________.

Java's process of automatically "boxing up" a value inside an object

In the following code, which line has an error? Line 1 public interface Interface1 Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double){} Line 5 }

Line 4

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?

SavingsAccount.getNumberOfAccounts();

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

String str = Integer.toString(number);

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

System.out.println(Double.MAX_VALUE);

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

The code contains a syntax error and will not compile.

A class must implement the Serializable interface in order for the objects of the class to be serialized

True

When an "is a" relationship exists between objects, the specialized object has __________.

all of the characteristics of the general object plus additional characteristics

All fields declared in an interface __________.

are treated as final and static

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

After the header, the body of the method appears inside a set of __________.

braces, { }

In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0);

char[]

One or more objects may be created from a(n) __________.

class

Which of the following shows the inheritance relationships among classes in a manner similar to that of a family tree?

class hierarchy

A(n) __________ can be thought of as a blueprint that can be used to create a type of __________.

class, object

In memory, an array of String objects __________.

consists of elements, each of which is a reference to a String object

A class specifies the __________ and __________ that a particular type of object has.

fields, methods

A deep copy of an object __________.

is an operation that copies an aggregate object and all the objects that it references

Any ___________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is.

nonletter

What would be the results of executing the following code? StringBuilder str = new StringBuilder("Little Jack Horner "); str.append("sat on the "); str.append("corner");

str would reference "Little Jack Horner sat on the corner".

What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; }

180

If the data.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

The file, data.dat, will be created.

What is the term used for a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables?

wrapper class

Assume that the classes BlankISBN, NegativePrice, and NegativeNumberOrdered are exception classes that inherit from Exception. The following code is a constructor for the Book class. What must be true about any method that instantiates the Book class with this constructor? public Book(String ISBNOfBook, double priceOfBook, int numberOrderedOfBook) { if (ISBNOfBook == "") throw new BlankISBN(); if (priceOfBook < 0) throw new NegativePrice(priceOfBook); if (numberedOrderedOfBook < 0) throw new NegativeNumberOrdered(numberOrderedv); ISBN = ISBNOfBook; price = priceOfBook; numberedOrdered = numberOrderedOfBook; }

It must handle all of the possible exceptions thrown by the constructor or have its own throws clause specifying them.

Classes that inherit from the Error class are for exceptions that are thrown when __________.

a critical error occurs, and the application program should not try to handle them

A class's responsibilities include __________.

both of these


Kaugnay na mga set ng pag-aaral

Histology of Accessory Digestive Organs

View Set

AP Psych Unit 2 Multiple Choice!!

View Set

What are the fundamental political principles that have shaped government in the United States?

View Set

Essentials of Pediatric Nursing - Chapter 24

View Set

P1U3 Unit Exam - Milady Standard Esthetics: Fundamentals (Chapters 1, 20, 23) - Flashcards only

View Set

[STATISTICS]-"Population and Sample"

View Set