Chapter 9 Inheritance, Chapter 11: Exception Handling, Java Quizzes 10-end, Ch. 10

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

What is the relationship between superclass and subclass types?

A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.

An advantage of inheritance is that: a. All methods can be inherited. b. All instance variables can be uniformly accessed by subclasses and superclasses. c. Objects of a subclass can be treated like objects of their superclass. d. None of the above.

C. Objects of a subclass can be treated like objects of a superclass.

Collections method sort that accepts a List as an argument sorts the elements of a List, which must implement the ____ interface.

Comparable

If an ObjectInputStream is used to read information from the server, an _____ is generated when the client attempts to read a value from a stream on which end-of-stream is detected.

EOFException

True or False? A non-generic class cannot be derived from a generic class.

False

True or false: UDP is a connection-oriented protocol.

False

______ enables programmers to specify, with a single method declaration, a set of related methods.

Generic methods

A(n) ______ allows a program to walk through the collection and remove elements from the collection.

Iterator

A(n) ______ is thrown when a String that is not in proper URL format is passed to a URL constructor

MalformedURLException

The preferred means of creating multithreaded java applications is by implementing the ____ interface. An object of a class that implements this interface represents a task to perform.

Runnable

______ sockets and the ______ protocol are more desirable for the vast majority of Java programmers.

Stream, TCP

In the catch block below, what is arithmeticException? catch(ArithmeticException arithmeticException){ system.err.print(arithmeticException); }// end catch

The name of catch block's exception parameter

A(n) is thrown when a server address indicated by a client cannot be resolved

UnknownHostException

Which method is NOT implicitly final?

a method in an abstract class

Which of the following statements about interfaces is false? a. An interface describes a set of methods that can be called on an object, providing a default implementation for the methods. b. An interface describes a set of methods that can be called on an object, not providing concrete implementation for the methods. c. Interfaces are useful when attempting to assign common functionality to possibly unrelated classes. d. Once a class implements an interface, all objects of that class have an is-a relationship with the interface type.

a. An interface describes a set of methods that can be called on an object, providing a default implementation for the methods.

To avoid duplicating code, use ________, rather than ________. a. inheritance, the "copy-and-past" approach. b. the "copy-and-paste" approach, inheritance. c. a class that explicitly extends Object, a class that does not extend Object. d. a class that does not extend Object, a class that explicitly extends Object.

a. Inheritance, the "copy and paste" approach.

Which of the following statements regarding the throw point of an exception is false? a. It specifies the point at which the exception must be handled. b. It is the initial point at which the exception occurs. c. It is specified as the top row of the method-call stack at the time the exception occurred. d. All of the above statements are true.

a. It specifies the point at which the exception must be handled.

Superclass methods with this level of access cannot be called from subclasses. a. private. b. public. c. protected. d. package.

a. Private level access

The default equals implementation of class Object determines: a. whether two references refer to the same object in memory. b. whether two references have the same type. c. whether two objects have the same instance variables. d. whether two objects have the same instance variable values.

a. Whether two references refer to the same object in memory.

Which of the following statements about abstract superclasses is true? a. abstract superclasses may contain data. b. abstract superclasses may not contain implementations of methods. c. abstract superclasses must declare all methods as abstract. d. abstract superclasses must declare all data members not given values as abstract.

a. abstract superclasses may contain data.

Which of the following statements about abstract superclasses is true? a. abstract superclasses may contain data b. abstract superclasses may not contain implementations of methods c. abstract superclasses must declare all methods as abstract d. abstract superclasses must declare all data members not given values as abstract.

a. abstract superclasses may contain data.

In Java, after an exception is handled, control resumes ---------. This is known as the------model of exception handling. a. after the last catch block (or the finally block, if there is one), termination b. after the last catch block (or the finally block, if there is one), resumption c. just after the throw point, termination d. just after the throw point, resumption

a. after the last catch block (or the finally block if there is one), termination.

After a finally block has finished executing (and there are no exceptions to be handled), ________. a. control proceeds to the first statement after the finally block. b. control returns to the throw point. c. the application exits. d. control proceeds to the first statement after the last catch block.

a. control proceeds to the first statement after the finally block.

Which of the following statements is true? a. The throw statement is used to throw an exception. b. The throw statement is used to specify that a method will throw an exception. c. The throw statement is used to access an exception parameter. d. All of the above.

a. the Throw statement is used to Throw an Exception.

Which of the following statements about try blocks is true? a. the try block should contain statements that may throw an exception b. the try block must be followed by a finally block c. the try block should contain statements that may process an exception d. the try block must be followed by at least one catch block.

a. the try block should contain statements that may throw an exception

A(n) _____ class cannot be instantiated.

abstract

A(n) class cannot be instantiated.

abstract

Once the ServerSocket is created, the server can listen indefinitely (or block) for an attempt by a client to connect. This is accomplished with a call to the ServerSocket method ____

accept

What is an uncaught exception?

an exception that occurs for which there are no matching catch clauses.

Which of the following is false? a. A subclass is often larger than its super class. b. A super class is object is a subclass object. c. The class following the extends keyword in a class declaration is that direct super class of the class being declared. d. Java uses interfaces to provide the benefits of multiple inheritance

b. A super class object is a subclass object.

private fields of a superclass can be accessed in a subclass a. by calling private methods declared in the superclass. b. by calling public or protected methods declared in the superclass. c. directly. d. All of the above.

b. By calling public or protected methods in the super class.

Which of the following statements is false? a. Exception handling enables programmers to write robust and fault-tolerant programs. b. Exception handling can catch but not resolve exceptions. c. Exception handling can resolve exceptions. d. All of the above are true.

b. Exception handling can catch but not resolve exceptions

Which of the following exceptions is a checked exception? a. ArithmeticException. b. IOException. c. RuntimeException. d. InputMismatchException.

b. IOException

Which of the following is the superclass constructor call syntax? a. keyword super, followed by a dot (.) . b. keyword super, followed by a set of parentheses containing the superclass constructor arguments. c. keyword super, followed by a dot and the superclass constructor name. d. None of the above.

b. Keyword super, followed by a set of parentheses containing the superclass constructor arguments.

Every class in Java, except ________, extends an existing class. a. Integer. b. Object. c. String. d. Class.

b. Object

Overriding a method differs from overloading a method because: a. Overloaded methods have the same signature. b. Overridden methods have the same signature. c. Both of the above. d. Neither of the above.

b. Overridden methods have the same signature.

Using the protected keyword also gives a member: a. public access. b. package access. c. private access. d. block scope.

b. Package access

In the catch block below, what is e? catch (ArithmeticException e) { System.err.printf(e); } a. The type of the exception being caught. b. The name of catch block's exception parameter. c. A finally block. d. An exception handler.

b. The name of catch block's Exception parameter.

Which of the following is not true of ExecutorService? a. it is a subinterface of executor b. it is an object that can be run in a separate thread. c. it declares method shutdown d. it manages a group of threads

b. it is an object that can be run in a separate thread

Which superclass members are inherited by all subclasses of that superclass? a. private instance variables and methods. b. protected instance variables and methods. c. private constructors. d. protected constructors.

b. protected instance variables and methods.

Which method changes the text the label displays? a. changeText. b. setText. c. changeLabel. d. setLabel.

b. setText

Which of the following statements is false? a. All exceptions must derive from the class Throwable. b. The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream. c. The class Throwable provides the method getMessage that returns the descriptive string stored in an exception. d. The string returned from class Throwable's getMessage method contains the name of the exception's class.

b. the class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.

If the catch-or-declare requirement for a checked exception is not satisfied ________. a. the compiler will issue an error message indicating that the exception must be caught. b. the compiler will issue an error message indicating that the exception must be caught or declared. c. a stack trace will be displayed indicating the exception that has occurred and where it occurred. d. a stack trace will be displayed, along with a message indicating that the exception must be caught.

b. the compiler will issue an error message indication that the exception must be caught or declared.

When an exception occurs it is said to have been ________. a. caught. b. thrown. c. declared. d. handled.

b. thrown

Consider the abstract superclass below: public abstract class Foo { private int a; public int b; public Foo(int aVal, int bVal) { a = aVal; b = bVal; } // end Foo constructor public abstract int calculate(); } //end class foo Any concrete subclass that extends class Foo: a. must implement a method called calculate b. will not be able to access the instance variable a. c. will not be able to instantiate an object of class Foo.

both (a) and (b)

For which of the following would polymorphism not provide a clean solution? a. A billing program where there is a variety of client types that are billed with different fee structures. b. A maintenance log program where data for a variety of types of machines is collected and maintenance schedules are produced for each machine based on the data collected. c. A program to compute a 5% savings account interest for a variety of clients. d. An IRS program that maintains information on a variety of taxpayers and determines who to audit based on criteria for classes of taxpayers.

c. A program to compute a 5% savings account interest for a variety of clients. Because there is only one kind of calculation, there is no need for polymorphism.

Which of the following statements is false? a. A class can directly inherit from class Object. b. It's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires. c. If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. d. A class's instance variables are normally declared private to enforce good software engineering.

c. If the class you're inheriting from declares instance variables as private the inherited class can access those instance variable directly. (They have to be declared as protected for the inherited class to be able to access them)

Class ________ represents an image that can be displayed on a JLabel. a. Image. b. Icon. c. ImageIcon. d. IconImage.

c. ImageIcon

When overriding a superclass method and calling the superclass version from the subclass method, failure to prefix the superclass method name with the keyword super and a dot (.) in the superclass method call causes ________. a. a compile-time error. b. a syntax error. c. infinite recursion. d. a runtime error.

c. Infinite Recursion

An uncaught exception ________. a. is a possible exception that never actually occurs during the execution of the program. b. is an exception that occurs for which the matching catch clause is empty. c. is an exception that occurs for which there are no matching catch clauses. d. is another term for a thrown exception.

c. Is an exception that occurs for which there are no matching catch clauses

Which of the following statements is true? a. Using existing exceptions makes the program less robust. b. Always create your own exception classes. c. Like any other class, an exception class can contain fields and methods. d. The new exception class should extend RuntimeException if the program should be required to handle the exception.

c. Like any other class, an exception class can contain fields and methods.

Which of the following is not a superclass/subclass relationship? a. Employee/Hourly Employee. b. Vehicle/Car. c. Sailboat/Tugboat. d. None of the above.

c. Sailboat/Tugboat (they are both different type of boats, they would both be subclasses of superclass boat.)

Which of the following statements is false? a. A finally block is placed after the last catch block. b. A finally block typically releases resources acquired in the corresponding try block. c. The finally block and try block can appear in any order. d. A finally block is optional

c. The finally block and the try block can appear in any order.

What is the difference between a try block and a try statement? a. There is no difference; the terms can be used interchangeably. b. A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword. c. The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement. d. The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finally clauses together form a try block.

c. The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch an/or finally clauses together form a try statement.

To catch an exception, the code that might throw the exception must be enclosed in a ________. a. throws block. b. catch block. c. try block. d. finally block.

c. Try Block

Which of the following statements about the try-with-resources statement is false? a. The try-with-resources statement simplifies writing code in which you obtain a resource, use it in a try block and release the resource in a corresponding finally block.. b. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then the statement implicitly calls the resource's close method at the end of the try block. c. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then you explicitly call the resource's close method at the end of the try block. d. Each resource must be an object of a class that implements the AutoCloseable interface—such a class has a close method

c. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; the you explicitly call the resources close method at the end of the try block.

Chained exceptions are useful for finding out about ________. a. exceptions thrown using the chained keyword. b. checked exceptions only. c. an original exception that was caught before the current exception was thrown. d. the current exception's chain of superclasses.

c. an original exception that was caught before the current exception was thrown.

Which of the following is true? a. A precondition must be true when a method is invoked. b. A postcondition must be true when a method successfully returns to its caller. c. Both (a) and (b). d. Neither (a) nor (b).

c. both (a) and (b)

All exception classes inherit, either directly or indirectly, from ________. a. class Error. b. class RuntimeException. c. class Throwable. d. None of the above.

c. class Throwable

Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)? a. public int method1(); b. public int abstract method1(); c. public abstract int method1(); d. public int nonfinal method1();

c. public abstract int method1();

The throws clause of a method: a. specifies the exceptions a method catches. b. specifies the exceptions thrown by the calling method. c. specifies the exceptions a method throws. d. specifies the exceptions a method throws and catches.

c. specifies the exceptions a method throws.

Which statement is false? Normally an applet _____

can read files on any server that can be reached over the network

All exception classes inherit, either directly or indirectly from: ___

class Throwable.

Non-abstract classes are called _____.

concrete classes

Non-abstract classes are called:

concrete classes

Which of the following are types of assertions? a. Preconditions. b. Postconditions. c. Conditions in control statements. d. (a) and (b).

d. (a) and (b)

Consider the classes below, declared in the same file: class A { int a; public A() { a = 7; } } class B extends A { int b; public B() { b = 8; } } Which of the statements below is false? a. Both variables a and b are instance variables. b. After the constructor for class B executes, the variable a will have the value 7. c. After the constructor for class B executes, the variable b will have the value 8. d. A reference of type A can be treated as a reference of type B.

d. A reference of type A can be treated as a reference of type B.

Which statement best describes the relationship between superclass and subclass types? a. A subclass reference cannot be assigned to a superclass variable and a superclass reference cannot be assigned to a subclass variable. b. A subclass reference can be assigned to a superclass variable and a superclass reference can be assigned to a subclass variable. c. A superclass reference can be assigned to a subclass variable, but a subclass reference cannot be assigned to a superclass variable. d. A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.

d. A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.

Exceptions can be thrown by ________. a. the Java Virtual Machine. b. code in a try block. c. calls from a try block to other methods. d. All of the above.

d. All of the above

When an unchecked exception occurs in a method but is not caught, ________. a. the method-call stack is "unwound." b. the method terminates. c. all local variables in that method go out of scope. d. All of the above.

d. All of the above

Which statement is true when a superclass has protected instance variables? a. A subclass object can assign an invalid value to the superclass's instance variables, thus leaving an object in an inconsistent state. b. Subclass methods are more likely to be written so that they depend on the superclass's data implementation. c. We may need to modify all the subclasses of the superclass if the superclass implementation changes. d. All of the above.

d. All of the above are true

Consider the abstract superclass below: public abstract class Foo { private int a; public int b; public Foo( int aVal, int bVal ) { a = aVal; b = bVal; } // end Foo constructor public abstract int calculate(); } // end class Foo Any concrete subclass that extends class Foo: a. Must implement a method called calculate. b. Will not be able to access the instance variable a. c. Neither (a) nor (b). d. Both (a) and (b).

d. Both (a) and (b).

Inheritance is also known as the _______ a. knows-a relationship. b. has-a relationship. c. uses-a relationship. d. is-a relationship.

d. Inheritance is known as the is-a relationship.

Which of the following is not included in an exception's stack trace? a. A descriptive message for the exception. b. The method-call stack at the time the exception occurred. c. The name of the exception. d. Instructions on handling the exception.

d. Instructions on handling the exception

Which of the following statements is true? a. The code in a finally block is executed only if an exception occurs. b. The code in a finally block is executed only if an exception does not occur. c. The code in a finally block is executed only if there are no catch blocks. d. None of the above are true.

d. None of the above are true. The code in the finally block is always executed provided that the flow of control enters the corresponding try block.

Consider classes A, B and C, where A is an abstract superclass, B is a concrete class that inherits from A and C is a concrete class that inherits from B. Class A declares abstract method originalMethod, implemented in class B. Which of the following statements is true of class C? a. Method originalMethod cannot be overridden in class C—once it has been implemented in concrete class B, it is implicitly final. b. Method originalMethod must be overridden in class C, or a syntax error will occur. c. If method originalMethod is not overridden in class C but is called by an object of class C, an error occurs. d. None of the above.

d. None of the above.

The default implementation of method clone of Object performs a ________. a. empty copy. b. deep copy. c. full copy. d. shallow copy.

d. Shallow Copy

When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable? a. A syntax error occurs. b. A compile-time error occurs. c. A run-time error occurs. d. The program compiles and runs because the instance variables are initialized to their default values.

d. The program compiles and runs because the instance variables are initialized to their default values.

Which of the following statements about try blocks is true? a. The try block must be followed by at least one catch block. b. The try block must be followed by a finally block. c. The try block should contain statements that may process an exception. d. The try block should contain statements that may throw an exception.

d. The try block should contain statements that may throw an exception.

Which of the following errors is synchronous? a. Divide by zero. b. Arithmetic overflow. c. Unsuccessful memory allocation. d. All of the above.

d. all of the above

Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method? a. base. b. this. c. public. d. super.

d. super (must be called in the default constructor of the subclass)

When the compiler translates a generic method into java bytecodes, it uses _____ to replace the type parameters with actual types.

erasure

Polymorphism allows for specifics to be dealt with during ___

execution

Polymorphism allows for specifics to be dealt with during:

execution

Which keyword is used to specify that a class will define the methods of an interface?

implements

If the superclass contains only abstract method declarations, the superclass is used for:

interface inheritance

Declaring a method final means: ___

it cannot be overridden

It is a UML convention to denote the name of an abstract class in:

italics

The classes and interfaces which comprise the collections framework are members of package ___

java.util

The main method executes in the ____ thread of execution

main

A new thread begins its life cycle by transitioning to the ___ state.

new

One generic Stack class could be the basis for creating many Stack classes, e.g., StackMDouble>, Stack<Integer>, and Stack<Employee>. These classes are known as:

parameterized classes

The collections framework algorithms are ___, i.e., each of these algorithms can operate on objects that offer given interfaces without concern to the underlying implementations

polymorphic

Polymorphism enables you to:

program in the general

Polymorphism enables you to:

program in the general.

When a generic class is instantiated without specifying a type argument, it is said to have a ___

raw type

Using a URL as an argument to the ___ method of interface AppletContext causes the browser in which an applet is executing to display the URL.

showDocument

When a ___ method or block is running on an object, the object is locked so no other such method can run on that object at the same time.

synchronized

To catch an exception, the code that might throw the exception must be enclosed in a ___

try block

A JEditorPane generates HyperlinkEvents ONLY if it is _____

uneditable


Conjuntos de estudio relacionados

Early Republic and Federalist Control

View Set

FILING INFORMATION/TAX WITHOLDING AND ESTIMATED TAX

View Set

1601 Quiz 11 Information Security Fundamentals

View Set

Chapter 6 Intro to Research Methods

View Set

Ch.12 physics test practice questions

View Set

Test 3 (Chapters 16.3-16.6 & 17) Deadline 4/13/18 by 5:00 pm

View Set

BIO 202 learnsmart: the female reproductive system

View Set

CH 2. Constitutional Democracy: Promoting Liberty and Self-Government

View Set

402: Basic Project Management & Reporting Skills

View Set

Microeconomics, Exam 3; Chapter 15

View Set