Programming FINAL EXAM

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

some way to control the number of time it repeats

Like a loop, a recursive method must have

Because every class directly or indirectly inherits from the Object class

every class inherits the Object class's members.

A class must implement the Serializable interface

in order for the objects of the class to be serialized.

base case

The ________ is at least one case in which a problem can be solved without recursion.

class hierarchy

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

Indirect recursion

________ occurs when method A calls method B which in turn calls method A.

instanceOf

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

package

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

recursive case

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

public class ClassA implements Interface1, Interface2

What statement correctly specifies two interfaces?

public class Salaried extends PayType

What statement declares Salaried as a subclass of PayType?

the first catch clause that can handle the exception.

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 Question options:

the exception will have a null message

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

methods that use UTF-8 encoding.

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

extends

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

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.

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.

the subclass constructor DOES NOT always execute before the superclass constructor.

In an inheritance relationship

inheritance

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

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

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

greatest common denominator binary search Towers of Hanoi

What problems can be solved recursively?

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

What statement gives an alternative way to write the following: FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream inputFile = new DataInputStream(fstream);

can also be solved iteratively, with a loop.

Any problem that can be solved recursively

multi-catch

Beginning with Java7, you can use ________ to reduce a lot of duplicated code in a try statement needs to catch multiple exceptions, but performs the same operation for each one.

5

Given the following code that uses recursion to find the factorial of a number, how many times will the else clause be executed if n = 5?private static int factorial(int n){if (n == 0)return 1;elsereturn n * factorial(n - 1);}

overrides

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

file.seek(8);

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?

The file, data.dat, will be created.

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 depth of recursion.

In a recursive program, the number of times a method calls itself is known as

#

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

absolutely required to solve a problem.

Recursion is never

FileOutputStream and DataOutputStream

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

overhead

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

recursion so it stops the chain of recursive calls.

The recursive case requires

The array must be sorted

To use recursion for a binary search, what is required before the search can proceed?

binary file.

A file that contains raw binary data is known as a

it can be broken down into successive smaller problems that are identical to the overall problem.

A problem can be solved recursively if

More than one base case

A recursive method can have

only public and protected members of the superclass.

A subclass can directly access

try block

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

exception handler

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

Abstract

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

Are treated as final and static

All fields declared in an interface

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

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

The call stack

an internal list of all the methods that are currently executing.

The throws clause

causes an exception to be thrown.

In a try statement

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

If a class has fields that are objects of other classes

those classes need to implement the Serializable interface to be serialized.

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

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

serves as a superclass for other classes.

An abstract class is not instantiated itself but

getMessage

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

a UML diagram

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

dashed line with an open arrowhead at one end.

In a UML diagram you show a realization relationship by connecting a class and an interface with a

if (x % y == 0)return y;

In the following code that uses recursion to find the greatest common divisor of a number, what is the base case?public static int gcd(int x, int y){if (x % y == 0)return y;elsereturn gcd(y, x % y);}

ClassA

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


Ensembles d'études connexes

Digestive System: Pharynx/Diglutition/Stomach/Pancreas/Liver/Gallbladder

View Set

QUIZ - Unit 5 - National Brokerage

View Set

Substance Use and Misuse - EXAM 2 - Dr.Johnny Moore

View Set

Anatomy & Physiology Exam 3 (Ch. 8-10)

View Set

Economic Systems: Adam Smith and the US Economy

View Set