CSCD 226       Exam #2                                               Name_________________________
100 points                                                                    Section_______

Short Answer (please attempt to write clearly)

1.        (6 points) (a) How are private members of the base class treated with respect to the derived class? (b) Can they be accessed from the derived class? (c) Explain.

 

 

 

 

 

2.        (6 points) How does method override differ from method overload? (describe each for full credit)

 

 

 

 

 

 

3.        (8 points) Explain how method override promotes reuse of code and polymorphic behavior.

 

 

 

 

 

 

4.        (15 points) Describe how you would set up the three main exception handling components in Java (try, throw, and catch).  For full credit, describe what purpose each thing serves and how they work together.

 


True or False (4 points each) -- Circle T or F --Briefly justify your answer
NOTE: YOU GET 2 POINTS FOR CORRECTLY ANSWERING T/F AND 2 POINTS FOR CORRECTLY JUSTIFYING YOUR ANSWER

5.        T / F  The messages printed by a thrown exception indicate the nature of the problem and a call stack trace that shows the methods that were invoked.

 

 

6.        T / F  If an exception is not caught and handled where it occurs, a run-time error is generated.

 

 

7.        T / F  A thrown exception can only be caught by one catch block.

 

 

8.        T / F  An object of a derived class can be treated as an object of its corresponding base class.

 

 

9.        T / F  Assigning a derived class reference to a base class reference will NOT generate a compiler error.

 

 

10.     T / F  For a derived-class object, first the base-class constructor is called, then the derived-class constructor is called (base class constructor executes first).

 

 

11.     T / F  You are not allowed to create your own exception handling class in Java.  You can only use the classes provided in the exception handling hierarchy.

 

 

12.     T / F  You are not required to call the base class constructor from a derived class constructor.

 

13.     T / F  It is possible to cast a base-class reference to a derived-class reference. The target, however, should be a derived class object.

 

14.     T / F  Every class in Java is part of an inheritance hierarchy.


More short answer

15.     (8 points) (a) Describe polymorphism.  (b) Give an example of a polymorphic reference in Java.  (c) Give an example of polymorphic behavior in Java.

 

 

 

 

 

 

 

 

 

16.     (12 points) (a) What is the fundamental characteristic of an abstract class?  (b) Why would you want to use one?  (c) Must an abstract class have an abstract method?  (d) What guarantees that a class derived from an abstract class will not itself be abstract?

 

 

 

 

 

 

 

 

 

 

17.     (5 points)  Why can a reference to an Exception object catch any exception that is derived from the Exception class?

 

 

 

 

EXTRA CREDIT (5 points)  What is a finally clause and why would you use one?