Java Reference
In-Depth Information
abstract method must be overridden.
4.9
Self-review exercises
SR1. If class C1 inherits from class C2 , then C1 is a _____________ of C2 and C2
is a _____________ of C1 .
SR2. Which generally has more functionality, a subclass or its superclass?
SR3. True or false? Casting an object of a subclass to its superclass type is a nar-
rowing cast.
SR4. True or false? Casting an object of a subclass to its superclass type can be
done automatically.
SR5. Defining two methods with the same name within a class is called ______.
Redefining a method of a superclass within a subclass is called ______
SR6. Give an example of each of the two ways of using keyword this .
SR7. Give an example of each of the two ways of using keyword super .
SR8 . What access modifier is used to hide fields of a superclass from its sub-
classes?
SR9 . Does it make sense to make an instance method private? Explain your
answer.
SR10. What class is the “superest” class of them all, in that it is a superclass of
all other classes?
SR11. Name two functions that are inherited by every single class you write?
SR12. If you override method equals(Object) , what properties should the new
method have?
SR13. How is the “is-a” relation used in object-oriented design?
SR14. True or false? You can create an instance of an abstract class.
SR15. What is a class invariant?
SR16. What is the public method overriding rule?
Answers to self-review exercises
SR1. C1 is a subclass of C2 and C2 is a superclass of C1 . SR2. Subclass. SR3.
false; it is a widening cast. SR4. True. SR5. Overloading and overriding. SR6.
meth( this ) calls method meth , giving it this instance as an argument. this (62)
calls the constructor of this class that has an int parameter. SR7. super .to-
String() calls the inherited toString function. super (62) calls the construc-
 
Search WWH ::




Custom Search