COP3022 - Final Study Guide

Ace your homework & exams now with Quizwiz!

Only ____ copy/copies of a static variable are available to objects of a class.

one

infinite recursion happens either because

the parameter values don't get simpler or because a special terminating case is missing

If a method does not catch a checked exception, then it must at least warn programmers that any invocation of the mthod might possibly throw the exception. This warning is called a/an:

Throw statement

A class definition can have more than one type parameter.

True

A class may implement multiple interfaces.

True

The call to the base class constructor from the derived class must always be the last action taken in a constructor definition.

False

The method to return the size of an array is called length.

False

To connect an Interface with a class, the keyword extends is used.

False

When an exception is thrown, the code in the surrounding try block continues executing and then the catch block begins execution.

False

You can use any primitive type as the base type of an ArrayList class.

False

A memory's stack region can store at most one stack frame.

False Each method call gets its own frame. Each frame has local method items like parameters, local variables, and the return value.

The size of the stack is unlimited.

False Memory is limited, so clearly stack size must be limited. Deep recursion could overflow the stack.

An abstract method serves as a placeholder for a method that must be defined in all derived classes.

True

ArrayList does not support primitive types.

True

ArrayList objects do not have the array square-bracket notation.

True

Each type parameter can be associated with type bounds to specify the data types a programmer is allowed to use for the type arguments.

True

The hardest kind of error to detect in a computer program is a:

Logic error

Java source code that contains a class with an inner class, when compiled, will product a separate .class for the inner class.

True

Runtime Polymorphism of Late binding refers to the method definition being associated with the method invocation when the method is invoked at runtime

True

The Java API Comparable interface, declares the compareTo() method.

True

The printf method can be used to output multiple formatted values.

True

The throw operator causes a change in the flow of control

True

When your program is finished writing to a file, it should close the stream connected to that file.

True

A stack overflow occurs when the stack frame for a method call extends past the end of the stack's memory.

True Such stack overflow usually causes the program to crash.

The following recursive method will result in a stack overflow. int recAdder(int inValue) { return recAdder(inValue + 1); }

True The method continues to make recursive calls. If the argument to the first call is 5, the recursive call passes 6, then 7, then 8, etc. Eventually, stack overflow occurs.

The compareTo method should return _____________ if the calling object equals the parameter.

Zero

If you write a student class, what must you do in order to write Student objects to a file using an ObjectOutputStream?

implement Serializable

A class that uses an interface must use the keyword:

implements

The keyword extends indicates:

inheritance

An interface type does not have ____.

instance fields

What does a derived class automatically inherit from the base class?

instance variables

Java allows an instance of abstract class to be instantiated

False

What does the following loop print? int total = 0; int n=0; for (n = 1; n<=5; n++) total = total + n; System.out.print(total + " ");

15

Method overloading is when two or more methods of the same class have the same name and the same number and type of parameters.

False

Objects of type String are strings of characters that are written within single quotes.

False

Primitive types are reference types.

False

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

ClassC

The principles of object oriented programming include:

Ecapsulation Inheritance Polymorphism All of the Above <------

Recursive Base Case

Every recursive method must have a case that returns a value without performing a recursive call. That case is called the base case. A programmer may write that part of the method first, and then test. There may be multiple base cases.

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

Exception Handler

The keyword _________ can be used to place a bound of a type parameter

Extends

A binary file contains ASCII information.

False

An ArrayList object has a fixed size.

False

An array variable stores the array object

False

An interface contains only instance variables that can be private or public.

False

An interface specifies the method headings and body.

False

Exceptions that must be caught or declared to be thrown are called unchecked exceptions.

False

In a switch statement, the choice of which branch to execute is determined by an expression given in parentheses after the keyword case.

False

Inner and Outer Classes do not have access to each other's private members.

False

N factorial (N!) is commonly implemented as a recursive method due to being easier to understand and executing faster than a loop implementation.

False While N! is widely used to introduce recursion, a loop implementation is likely more intuitive and faster too. N! is just a simple example for recursion; other algorithms are a better match for a recursive solution.

A derived class contains only public instance variables and public methods from the base class.

False.

Class and method definitions that include parameters for types are called:

Generics

Consider the following code snippet: PrintWriter out = new PrintWriter("output.txt"); Which of the following statements about the PrintWriter object is correct?

If a file named "output.txt" already exists, existing data will be deleted before data is added to the file.

What does the following statement do when it is executed? FileInputStream infile = new FileInputStream("InputFile.txt");

It creates a FileInputStream object and opens an input file called InputFile.txt.

The class __________ is an ancestor class of all Java classes.

Object

_________________ refers to the process of association a method definition with a method invocation.

Polymorphism

In searching for item C, findMatch(0, 2) is called. What happens next?

Recursive call: findMatch(2, 2) findMatch(0, 2) checks list[1]. C > B so the search proceeds to the right, so findMatch(1 + 1, 2) or findMatch(2, 2). That call will return -1 (no match).

Consider the following code snippet. FileInputStream inputFile = new FileInputStream("input.txt"); You wish to read the contents of this file using a Scanner object. Which of the following is the correct syntax for doing this?

Scanner in = new Scanner(inputFile);

Consider the following code snippet: public double[] readInputFile(String filename) throws IOEXception { File inputFile = new File(filename); Scanner in = new Scanner(inputFile); try { readData(in); return data; } catch (NoSuchElementException exception) { . . . } finally { inputFile.close(); } } Which of the following statements about this method's code is correct?

The file will be closed whether or not an exception occurs.

An object of a derived class has the type of the derived class, and it also has the type of the base class, and more generally, has the type of every one of its ___________ classes.

ancestor

All fields declared in an interface

are final and static

parts of a recursive method

base case or termination condition that causes the method to end nonbase case whose actions move the algorithm toward the base case and termination

Objects of the same kind are said to have the same type, or more often, are said to be of the same __________.

class

Inheritance is the process by which a new class - known as a __________ is created from another class, called the _________.

derived class, base class

degenerate inputs

empty strings, shapes with no area, etc...

A _______ block executes regardless of whether an exception occurs.

finally

A list has 5 elements numbered 0 to 4, with these letter values: 0: A, 1: B, 2: D, 3: E, 4: F. To search for item C, the first call is findMatch(0, 4). What is the second call to findMatch()?

findMatch(0, 2) findMatch(0, 4) checks list[2]. C < D so the search proceeds left calling the method to explore the lower half or findMatch(0, 2).

What is the correct expression for accessing the 5th element in an array named grade?

grade[4]

All of the following are methods of the ArrayList except

length() Note: get(), size(), add() are not methods of ArrayList

To pass array called people as a parameter in a method called mystery1, it must be in the following syntax:

mystery1(people);

The method that must be implemented in a class using the Comparable Interface is:

public void compareTo(Object other)

Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 without losing any other data in the ArrayList?

recVehicles.add(3, "boat");

Inheritance promotes code _________.

reuse

for a recursion to terminate there must be

special cases for the simplest values

The special syntax for invoking a constructor of the base class is:

super()

Try blocks contain code that could possibly

throw an exception

The execution of a throw statement:

throws an exception

Assigning an object of a derived class to a variable of a base class is called:

upcasting

The length of an array named values is accessed via the following code.

values.length


Related study sets

Methods of Investing- Personal Finance ch 14

View Set

President Theodore Roosevelt in the Progressive Era

View Set

Utah Life & Health Test Study Guide

View Set

Chapter 9: Flexible Budgets, Standard Costs, and Variance Analysis

View Set

Chapter 1: Physical Fitness & Wellness

View Set

Econ Chapters 1-5 Multiple Choice Questions

View Set

Semester One Final Social Studies Lewis Cass

View Set