CST240 Quiz 6-11

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

"has a"

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

"Has a"

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

Class

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

Primitive variable

What type of relationship exists between two objects when one object is a specialized version of another object?

"is a"

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

A constructor ________.

Has the same name as the class

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

True

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

True

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

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

True

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

True

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.

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

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

True

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

a case expression

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

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

a throws clause in its header

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 of the String class can be used to tokenize a string

split

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

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

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

the program will terminate

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

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

import java.String;

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

A wildcard import

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

Instance methods

What will be displayed after the following code is executed? StringBuilder strb = new StringBuilder(12); strb.append("The cow "); strb.append("jumped over the "); strb.append("moon."); System.out.println(strb);

The cow jumped over the moon.

StringBuilder objects are not immutable.

True

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

True

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

True

enum constants have a toString method.

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.

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

nonletter

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

numbers[r].length

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

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

try block

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

unchecked and checked

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

True

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

+

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

Serializable

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

int x = Integer.parseInt(str);

Which of the following is not true about static methods?

They are called from an instance of the class.

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

They have different parameter lists

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.

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

False

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

Fields private

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

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

Static

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()); for (int i = 0; i < names.length; i++)

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

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

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

Declaring an array reference variable does not create an array.

True

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

True

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

True

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 an "is a" relationship exists between objects, the specialized object has ________.

all of the characteristics of the general object plus additional characteristics

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

an unchecked exception class

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

garbage collection

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

long[]

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

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

multi-catch

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

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

the address of an object of the Rectangle 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

In an inheritance relationship ________.

the superclass constructor always executes before the subclass constructor

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

true

A partially filled array is normally used ________.

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

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

|

You can declare an enumerated data type inside a method.

False

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

To compare two objects in a class, ________.

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

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}

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

123, 456,7890

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 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 following statement is an example of ________. import java.util.Scanner;

An explicit import

A protected member of a class may be directly accessed by ________

Any of these

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

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

False

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

False

Select all that apply. Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];

It creates an instance of an array of ten long values. It will allow valid subscripts in the range of 0 through 9. It declares array1 to be a reference to an array of long values.

All fields declared in an interface ________.

are treated as final and static

The ________ indicates the number of elements the array can hold

array's size declarator

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

ordinal

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

overrides

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

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

protected

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

#

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

0

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

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

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

FileOutputStream and DataOutputStream

Overloading means that multiple methods in the same class ________.

Have the same name, but different parameter lists

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

NumberFormatException

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

Package

A constructor is a method that ________.

Performs initialization or setup operations.

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

The insert will start at position 32.

The scope of a private instance field is ________.

The instance methods of the same class

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

The method header must begin with the key word default.

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

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

A class's responsibilities include ________.

The things a class is responsible for doing & for knowing (Both

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.

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

The variable name followed by a colon and the data typ

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

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

initialization list

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

state

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

substring

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

super

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

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

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

True


Ensembles d'études connexes

Quiz 3- Chapters 5, 18 & 19 (True/False)

View Set

Mod 9 Health Information Privacy and Security Review

View Set

Health Unit 4 Body Composition video

View Set

Routes of Medication Administration

View Set