CMSC 132 QUIZ 2
Immutable - answer unchangeable
modification of the state within the class is ___________ - answer expected
T/F : direct mutation by external code should not be possible! – answer T
When using the comparable interface, what would the class header look like? (use the
Dog example for reference) - answer public class Dog implements Comparable<Dog>
if you use the comparable interface, what method do you have to implement? – answer
compare To- defines the natural order
public void take Bath(Bird b)
1) what kind of objects can b represent?
2)what methods can be called on b? – answer b can represent itself and any
subclasses
any methods in the animal class or bird class
if there is an eat method in the subclass bird and superclass animal, which method is
called with b.eat( ) - answerthe one in the subclass- thats the whole idea behind
overriding
https://docs.google.com/spreadsheets/d/1pNVEAum-
5bPUAY9mZmjdJF_cP9XIxkkJrOy3zHxr8Cc/edit?usp=sharing - answer
class X extends Y implements A, B, C {...} - answerX is a subclass of Y (Y is the
superclass of X)
•A, B, C are interfaces
•X can only extend ONE thing
•X can implement many interfaces•X inherits all features of Y
•X must implement all unimplemented methods in A, B, C
•X "is a" Y (LiskovSubstitution Principle)
•X "can do" A, B, C
•An instance of X can be assigned to variables of types X, Y, A, B, C.
•An instance of X satisfies types X, Y, A, B, C
•An instance of X is only "class X".
c.contains(a) - answerTRUE if there is an element in the collections that is equal to a
default equals method is the same as - answer== (aliasing)
Immutable - answer unchangeable
modification of the state within the class is ___________ - answer expected
T/F : direct mutation by external code should not be possible! – answer T
When using the comparable interface, what would the class header look like? (use the
Dog example for reference) - answer public class Dog implements Comparable<Dog>
if you use the comparable interface, what method do you have to implement? – answer
compare To- defines the natural order
public void take Bath(Bird b)
1) what kind of objects can b represent?
2)what methods can be called on b? – answer b can represent itself and any
subclasses
any methods in the animal class or bird class
if there is an eat method in the subclass bird and superclass animal, which method is
called with b.eat( ) - answerthe one in the subclass- thats the whole idea behind
overriding
https://docs.google.com/spreadsheets/d/1pNVEAum-
5bPUAY9mZmjdJF_cP9XIxkkJrOy3zHxr8Cc/edit?usp=sharing - answer
class X extends Y implements A, B, C {...} - answerX is a subclass of Y (Y is the
superclass of X)
•A, B, C are interfaces
•X can only extend ONE thing
•X can implement many interfaces•X inherits all features of Y
•X must implement all unimplemented methods in A, B, C
•X "is a" Y (LiskovSubstitution Principle)
•X "can do" A, B, C
•An instance of X can be assigned to variables of types X, Y, A, B, C.
•An instance of X satisfies types X, Y, A, B, C
•An instance of X is only "class X".
c.contains(a) - answerTRUE if there is an element in the collections that is equal to a
default equals method is the same as - answer== (aliasing)