discuss type definition, class types, array types, value of typesincludes examples and figure
Key point #2: subtype relationship
discuss list of items which if satisfied means a class is a sub type of another
discuss super class vs. sub class includes example
Key point #3: Wrapper Classes
Key point #4: Equality Testing
discuss .equals() method vs '=='technical requirementsincludes example
Key point #5: Enumerated types
discuss; includes example
Key point #6: Type Inquiry
discuss getting type name, testing type with instance of, type inquiry with arrays
Key point #7: Object Class
discuss class and methodsdiscuss toString method
Key point #8: Hashing
discuss strategy and related classes and defaul implementationincludes example code
Key point #9: Shallow copy vs. Deep Copy
discuss shallow copy and deep copy definiation
Key point #10: Overriding Object Methods
discuss ability and solutionsdiscuss methods which cannot be overriddendiscuss methods which must be overridden
Include any diagrams or illustrations you present
Give two short exam questions (and solutions) about your topic.
Question #1:
What is the difference between using the .equals() method to check equality versus using '=='? Name and explain two of the four technical requirement the Java Language Specification imposes on the equals method.
Solution #1:
The x.equals(y) method is used to test whether x and y are references to two objects, that may be distinct, have the "equal" contents. The '==' operator (x == y) tests whether x and y are two references to the same object. The four requirements are: 1)it is reflexive - for any reference value x, x.equals(x) should return true, 2)it is symmetric - for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true, 3)it is transitive - for any reference values x, y and z, if x.equals(y) return true and y.equals(z) returns true, then x.equals(z) should return true, 4)For any non-null reference value x, x.equals(null) should return false.
Question #2:
What is the difference between a shallow copy and a deep copy?
Solution #2:
A shallow copy makes a new object of the same type as the original and copies the values of all the fields. A shallow copy copies the object itself, but not any of the other objects that the first object refers to. The copy will refer to the same objects as the original object. A deep copy copies the object and all objects it refer to, and any objects those might refer to and so on.