Chapters 9&10

Ace your homework & exams now with Quizwiz!

Unchecked exceptions are those that inherit from the

Error class or the RuntimeException class

To read data from a binary file, you create objects from the following classes:

FileInputStream and DataInputStream

To write data to a binary file, you create objects from the following classes:

FileOutputStream and DataOutputStream

When you deserialize an object using the readObject method, you must cast the return value to the desired class type. (true/false)

True

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

UML diagrams

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

a chain of inheritance

This shows the inheritance relationships among classes in a manner that is similar to a family tree.

class hiearchy

In a ____ ______, the more general classes are toward the top of the tree and the more specialized classes are toward the bottom.

class hierarchy

System.out.println(e.getMessage()); prints the _____ message for an exception

error

When one object is a specialized version of another object, there is this type of relationship between them.

"is a"

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

#

This is a section of code that gracefully responds to exceptions when they are thrown.

exception handler

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

getMessage

If a program does not handle an unchecked exception, what is the result? The program is _____ and the _____ ______ ______ handles the exception.

halted, default exception handler

What will be the result of the following statements? FileInputStream fstream = new FileInputStream("Input.dat"); DataInputStream inFile = new DataInputStream(fstream); The _____ variable will reference an object that is able to read binary data from the ______ file.

inFile, Input.dat

In object-oriented programming, ________ allows you to extend the capabilities of a class by creating another class that is a specialized version of it.

inheritance

When a class implements an interface, an inheritance relationship known as ________ is established.

interface inheritance

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

WriteObject

catch (Exception e) can handle all exceptions that are instances of the Exception class or one of its subclasses. true/false)

true

When an exception is thrown by code in the 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 ____ ____ _____ with a parameter that is compatible with the exception

first catch clause

If you do not provide an access specifier for a class member, the class member is given ________ access by default.

package

When you deserialize an object using the readObject method, you must cast the return value to the desired class type. (true/false)

true

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

try block

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

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

If a subclass constructor does not explicitly call a superclass constructor, Java will automatically call the ________ ________ _______ just before the code in the subclass's constructor executes.

superclass's default constructor

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/false)

true

The call stack is an internal list of all the methods that are currently executing. (true/false)

true

You can use this operator to determine whether an object is an instance of a particular class.

instanceof

When an exception is thrown, it must be handled by the program or by the default exception handler. (true/false)

true

public class ClassA implements Interface1, Interface2 The above specifies how many interfaces?

2

When a class does not use the extends key word to inherit from another class, Java automatically extends it from the ________ class.

Object

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

Serializable

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.

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

a throws clause in its header

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

abstract

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 in Java 7, you can use ________ to reduce a lot of duplicated code in a try statement that needs to catch multiple exceptions, but perform the same operation for each one.

multi-catch

When using the throw statement, if you do not pass a message to the exception object's constructor, the exception will have a ____ _________.

null message

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

overrides

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

protected

A subclass can directly access only public and _______ members of the superclass.

protected

All methods specified by an interface are

public

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

public class Salaried extends PayType

FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream input file = new DataInputStream(fstream); could also be written as

DataInputStream inputFile = new DataInputStream(new FileInputStream("info.dat"));

Classes that inherit from the _____ class are for exceptions that are thrown when a critical error occurs, and the application program should not try to handle them.

Error

Unchecked exceptions are those that inherit from the

Error class or the RuntimeException class.

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

Exception

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

abstract method

A file that contains raw binary data is known as a(n)

binary file

The RandomAccessFile class treats a file as a stream of

bytes

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

final

All fields declared in an interface are treated as ______ and _______.

final, static

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

exception

This key word indicates that a class inherits from another class.

extends

In an inheritance relationship, the subclass constructor always executes before the superclass constructor. (true/false)

false

The throw statement informs the compiler that a method throws one or more exception. (true/false)

false

The throws clause causes an exception to be thrown. (true/false)

false

When you write a method that throws a checked exception, you must have a _____ clause in the method header.

throws

A class must implement the Serializable interface in order for objects of the class to be serialized. (true/false)

true

An abstract class is not instantiated itself, but serves as a superclass for other classes. (true/false)

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/false)

true

If a class has fields that are objects of other classes, those classes must implement the Serializable interface in order to be serialized. (true/false)

true

In Java, there are two categories of exceptions:

unchecked and checked

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

ClassC

You show inheritance in a UML diagram by connecting two classes with a line that has an open arrowhead that points to the subclass. (true/false)

false

In a UML diagram, you show a realization relationship by connecting a class and an interface with a dashed line that has an open arrowhead at one end. (true/false)

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/false)

true

When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object. (true/false)

true

When an "is a" relationship exists between objects, it means that the specialized object has all the characteristics of the general object, plus additional characteristics that make it special. (true/false)

true

When an "is a" relationship exists between objects, it means that the specialized object has all of the characteristics of the general object, plus additional characteristics that make it special. (true/false)

true

When an object is serialized, it is converted into a series of bytes that contain the object's data. (true/false)

true

When catching multiple exceptions that are related to one another through inheritance, you should handle the more specialized exception classes before the more general exception classes. (true/false)

true

You can write a super statement that calls a superclass constructor, but only in the subclass's constructor. (true/false)

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/false)

true


Related study sets

Chap 2: The Interview aand Health History

View Set

Marketing Management - Iacobucci - Ch 14

View Set

5.2.14 (Outline the role of feedback with the learning process

View Set