Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) If an exception is not caught, a program will _____________________ . a) Not

ID: 3556486 • Letter: 1

Question

1) If an exception is not caught, a program will _____________________ .

a)     Not compile

b)     Terminate abnormally

c)     Print a message and continue executing

d)     All of the above

e)     Neither a, b nor c

3) The first call to invoke a recursive method is

a)     Not recursive

b)     Recursive

c)     The recursion step

d) None of the above

2) Which of the following statement is false?

a)     Inner class listeners can be shortened using anonymous inner classes.

b)     An anonymous inner class is an inner class without a name.

c)     Inner classes can make programs simple and concise.

d)     An inner class supports the work of its containing outer class.

e)     An anonymous inner class must implement all the abstract methods in the superclass or in the interface.

f)      A static inner class can access non-static members of the outer class.

3) Suppose we would like to declare a generic type Group that only allows types that implement the Comparable interface. Which of the following declarations correctly declares such a class?

a)     Class Group<Comparable> {

b)     Class Group<T (Comparable)>

c)     Class Group<T instanceof Comparable>

d)     Class Group<T extends Comparable<T>>

e)     Class Group<T>

Explanation / Answer

1)

Exception enables a method to throw an exception to its caller. The caller can handle this exception. A try-catch block is used only when an exception occurs. If no exception occurs, the catch blocks are skipped. If there is an exception and it is not caught, then the program will terminate abnormally.

Hence, the correct answer is b (Terminate abnormally).

3)

The first call to invoke a recursive method is not recursive.

The first call will be made in the main() function. This will not be recursive. The remaining calls to that are made within the recursive method are recursive.   

Hence, the correct answer is a (Not recursive).

2)

a)    Inner class listeners can be shortened using anonymous inner classes. --TRUE

b)     An anonymous inner class is an inner class without a name. --TRUE

c)     Inner classes can make programs simple and concise.-- TRUE

d)     An inner class supports the work of its containing outer class. --TRUE

e)     An anonymous inner class must implement all the abstract methods in the   

        superclass or in the interface. –TRUE

f)      A static inner class can access non-static members of the outer class. – FALSE

        A non-static inner class can access both the static and non-static members of the

        outer class whereas a static inner class cannot access the non-static members of

        the outer class.

Hence, the correct answer is F .

3)

The correct declaration to declare a generic type Group that only allows types that implement the Comparable interface is

Class Group<T extends Comparable<T>>

Hence, the correct answer is d.