Chapter 10 and 11

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

If the program does not handle an unchecked exception: the exception is ignored the program is halted and the default exception handler handles the exception the program must handle the exception this will cause a compilation error

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

If, within one try statement you want to have catch clauses of the following types, in which order should they appear in your program: (1) Exception (2) IllegalArgumentException (3) RuntimeException (4) Throwable 1, 2, 3, 4 2, 3, 1, 4 4, 1, 3, 2 3, 1, 2, 4

2, 3, 1, 4

If, within one try statement you want to have catch clauses that catch exceptions of the following types, in which order should they appear in your program?(1) Throwable(2) Exception(3) RuntimeException(4) NumberFormatException 4, 3, 2, 1 2, 3, 1, 4 4, 1, 3, 2 3, 1, 2, 4

4, 3, 2, 1

This annotation tells the Java compiler that a method is meant to override a method in the superclass. @Override @Overload @Protected @Inherited

@Override

When an array is passed to a method __________ A) a reference to the array is passed B) it is passed just as an object C) the method has direct access to the original array D) All of the above

All of The Above

A protected member of a class may be directly accessed by: methods of the same class methods of a subclass methods in the same package All of these

All of these

a search algorithm _________________ a .arranges elements in ascending order b .arranges elements in descending order c. is used to locate a specific item in a collection of data d. is rarely used with arrays

C

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

ClassA

In the following statement, which is the superclass?public class ClassA extends ClassB implements ClassC ClassA ClassB ClassC Cannot tell

ClassB

What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE] // Code that will put values in array1 int value = 0; for (int a = 0; a < array1.length; a++) {value += array1[a]; } A) Value contains the highest value in array1. B) Value contains the lowest value in array1. C) Value contains the sum of all the values in array1. D) This would cause the program to crash.

D) This would cause the program to crash.

An exception's default error message can be retrieved using this method. getMessage() getErrorMessage() getDefaultMessage() getDefaultErrorMessage()

getMessage()

All of the exceptions that you will handle are instances of classes that extend this class. RunTimeException IOException Error Exception

Exception

In a catch statement, what does the following code do?System.out.println(e.getMessage()); It prints the stack trace. It prints the error message for an exception. It prints the code that caused the exception. It overrides the toString method.

It prints the error message for an exception.

Look at the following code and determine what the call to super will do. public class classB extends ClassA { public ClassB() { super(10); } } This cannot be determined form the code shown. It will call the constructor of ClassA that receives an integer as an argument. It will call the method named super and pass the value 10 to it as an argument. The method super will have to be defined before we can say what will happen.

It will call the constructor of ClassA that receives an integer as an argument.

The exception classes are in packages in the ________. Java API JVM Compiler Ex class

Java API

If a subclass constructor does not explicitly call a superclass constructor: it must include the code necessary to initialize the superclass fields the superclass fields will be set to the default values for their data types Java will automatically call the superclass's default or no-arg constructor immediately after the code in the subclass's constructor executes Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

If the code in a method can potentially throw a checked exception, then that method must: handle the exception have a throws clause listed in the method header neither handle the exception nor have a throws clause listed in the method header either handle the exception or have a throws clause listed in the method header

either handle the exception or have a throws clause listed in the method header

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

exception

The following catch statement can:catch (Exception e) {...} handle all exceptions that are instances of the Exception class, but not a subclass of Exception handle all throwable objects by using polymorphic reference as a parameter in the catch clause handle all exceptions that are instances of the Exception class or a subclass of Exception is an error since no objects are instantiated in the Exception class

handle all exceptions that are instances of the Exception class or a subclass of Exception

to return an array of long values from a method, which return type should be used for themethod?

long[]

The ability to catch multiple types of exceptions with a single catch is known as ________, and was introduced in Java 7. multi-catch super catch exception trapping compound catch

multi-catch

Which of the following statements declares Salaried as a subclass of PayType? public class Salaried extends PayType public class Salaried implements PayType public class Salaried derivedFrom(Paytype) public class PayType derives Salaried

public class Salaried extends PayType

What key word can you use to call a superclass constructor explicitly? goto this super extends

super

If a superclass does not have a default constructor or a no-arg constructor: Then a class that inherits from it, must initialize the superclass values. Then a class that inherits from it, must call one of the constructors that the superclass does have. Then a class that inherits from it, does not inherit the data member fields from the superclass. Then a class that inherits from it, must contain the default constructor for the superclass.

then a class that inherits from it, must call one of the constructors that the superclass does have.

In a multi-catch, (introduced in Java 7) the exception types are separated in the catch clause by this symbol: * ? | &

|

What will the following code display? String input = "99#7"; int number; try { number = Integer.parseInt(input); } catch(NumberFormatException ex) { number = 0; } catch(RuntimeException ex) { number = 1; } catch(Exception ex) { number = -1; } System.out.println(number); A) 99 B) 997 C) 0 D) 1

0

If a class contains an abstract method: you cannot create an instance of the class the method will have only a header, but not a body, and end with a semicolon the method must be overridden in subclasses All of these

All of these

The catch clause: follows the try clause starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable contains code to gracefully handle the exception type listed in the parameter list All of thes

All of these

Replacing inadequate superclass methods with more suitable subclass methods is known as what? Method upgrading Tactical inheritance Method overriding Method overloading

Method overriding

The numeric classes' "parse" methods all throw an exception of this type if the string being converted does not contain a convertible numeric value. NumberFormatException ParseIntError ExceptionMessage FileNotFoundException

NumberFormatException

You can use the _________________ method to replace an item at a specific locationin an ArrayList

Set

What is wrong with the following code? public class ClassB extends ClassA { public ClassB(() { int init = 10; super(40); } } Nothing is wrong with the code. The method super is not defined. The call to the method super must be the first statement in the constructor. No values may be passed to super.

The call to the method super must be the first statement in the constructor.

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 for exceptions that are thrown when a critical error occurs, and the application program should try to handle them for exceptions that are thrown when an IOException occurs, and the application program should not try to handle them for exceptions that are thrown when an IOException error occurs, and the application program should try to handle them

for exceptions that are thrown when a critical error occurs, and the application program should not try to handle them

A subclass can directly access: all members of the superclass only public and private members of the superclass only protected and private members of the superclass only public and protected members of the superclass

only public and protected members of the superclass

If two methods have the same name but different signatures, they are: overridden overloaded superclass methods subclass methods

overloaded

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

package

In Java, a reference variable is __________ because it can reference objects of typesdifferent from its own, as long as those types are related to its type through inheritance

polymorphic

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

final

The try statement may have an optional ________ clause, which must appear after all of the catch clauses. try-again finally default abort

finally

A subclass may call an overridden superclass method by: prefixing its name with the super key word and a dot (.) prefixing its name with the name of the superclass in parentheses using the extends keyword before the method is called calling the superclass method first and then calling the subclass method

prefixing its name with the super key word and a dot (.)

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: each catch clause that can handle the exception. the last catch clause that can handle the exception. the first catch clause that can handle the exception. If there are two or more catch clauses that can handle the exception, the program halts.

the first catch clause that can handle the exception.

If a class contains an abstract method: you must create an instance of the class the method will have only a header, but not a body, and end with a semicolon the method cannot be overridden in subclasses All of these.

the method will have only a header, but not a body, and end with a semicolon

All exceptions are instances of classes that extend this class. RunTimeException Throwable Error Exception

Throwable

In a try/catch construct, after the catch statement is executed: the program returns to the statement following the statement in which the exception occurred the program terminates the program resumes at the statement that immediately follows the try/catch construct the program resumes at the first statement of the try statement

the program resumes at the statement that immediately follows the try/catch construct


Set pelajaran terkait

Finance: Chapter 10 - Making Capital Investment Decisions

View Set

Chapter 14 Workforce Engagement and Collective Action

View Set

Common Medications in Maternity Nursing NURS 509

View Set