2/26/08

To Notes

CSC 212 -- 2/26/08

 

Review Questions

  1. Given the inheritance hierarchy

    and the code how does the compiler decide which f is called?

    Ans: The compiler looks first in the class F. If an f method is defined, use it. Otherwise, search, in order, E, D, C, B, A, Object. Use the first f that is found. If no f is found, print an error message.

  2. Variable trace problem: Construct the variable trace and predict the output:

  3. Redo the Stack Example of Week 5 to accept Object objects. Note that we cannot insert primitive datatypes into this Stack. Use the corresponding wrapper class instead:

    Ans: Simply use the editor to replace all instances of the word Person with the word Object.

  4. How can an object determine from which class it was instantiated?

    Ans: If x is the object, use x.getClass( ).getName( ).

  5. Give an example that shows how the finalize method of the Object class works.

    Ans: TestFinalize.java   Person.java

 

Virtual Methods

 

Exceptions