Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

168 HOUR 12:Making the Most of Existing Objects



  1. What methods can you use to retrieve an element stored in a vector?
    A. get()
    B. read()
    C. elementAt()

  2. What statement can you use to refer to the methods and variables of
    the current object?
    A. this
    B. that
    C. theOther


Answers



  1. B.Because you can override the method,you don’t have to change any
    aspect of the superclass or the way it works.

  2. A.Theget()method has one argument—the index number of the ele-
    ment.

  3. A.Thethiskeyword refers to the object in which it appears.


Activities
If a fertile imagination has birthed in you a desire to learn more,you can
spawn more knowledge of inheritance with the following activities:

. Create a Point4Dclass that adds a tcoordinate to the (x,y,z) coordi-
nate system created by the Point3Dclass. The tcoordinate stands for
time,so you need to ensure that it is never set to a negative value.
. Ta ke t h e m e m b e r s o f a f o o t b a l l t e a m ’s o f f e n s e : l i n e m a n ,wide receiver,
tight end,running back,and quarterback. Design a hierarchy of classes
that represent the skills of these players,putting common skills higher
up in the hierarchy. For example,blocking is behavior that probably
should be inherited by the linemen and tight end classes,and speed is
something that should be inherited by wide receivers and running backs.


To s e e J av a p r o g r a m s t h a t i m p l e m e n t t h e s e a c t i v i t i e s ,visit the book’s website
at http://www.java24hours.com.
Free download pdf