Chapter 7- 10 java

¡Supera tus tareas y exámenes ahora con Quizwiz!

1. Which of the following problems can be solved recursively?

a. All of the Above i. binary search ii. towers of Hanoi iii. greatest common denominator

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

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

UML diagram

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

final

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.

6. In the following statement, which is the superclass? Public class ClassA extends ClassB implements ClassC

ClassB

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

Interface inheritance

8. A subclass can directly access?

Only public and protected member of the superclass

3. The actions performed by the JVM that take place with each method call are sometimes referred to as this.

Overhead

12. All methods specified by an interface are?

Public

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

Public class Salaried extend PayType

7. All fields declared in an interface?

Are treated as final and static

In a catch statement, what does the following code do?

It prints the error message for an exception.

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

Methods of a subclass, methods of the same class, methods in the same package.

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

Serializable

10. In a class hierarchy?

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

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

True

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

True

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

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

a throws clause in its header

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

bytes.

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

class hierarchy

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

7. When an exception is thrown,

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

4. In the ________, we must always reduce the problem to a smaller version of the original problem.

recursive case

2. Like a loop, a recursive method must have which of the following?

some way to control the number of times it repeats

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

try block

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

Abstract

9. Look at the following code: FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream inputFile = new DataInputStream(fstream); This code could also be written as

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

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

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

exception handler

19. You show inheritance in a UML diagram by connecting two classes with a line that has an open arrowhead that points to the subclass.

false

7. The recursive case does not require recursion, so it stops the chain of recursive calls

false

9. A recursive method can have no more than one base case.

false

10. Recursion is never absolutely required to solve a problem.

true

18. When a class contains an abstract method, you cannot create an instance of the class.

true

The catch clause

All of the above i. starts with the word catch followed by a parameter list in parentheses containing anExceptionType parameter variable. ii. contains code to gracefully handle the exception type listed in the parameter list. iii. follows the try clause

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

True

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

True

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

getMessage

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

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

6. Any problem that can be solved recursively can also be solved iteratively, with a loop.

true

8. A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.

true

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

#

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

True

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

True

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

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

the first catch clause that can handle the exception.


Conjuntos de estudio relacionados

Reynolds Islam and Christian Theology - FA17

View Set

Consumer Behavior Review Test One

View Set

STA1LS Semester 2, 2017 Revision

View Set

Religion: Unit 4: The Church is Catholic

View Set

DIFS ~ Small Business Management II ~ Part 1&2

View Set