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

(singke) #1
ptg7068951

136 HOUR 10:Creating Your First Object


Quiz



  1. What statement is used to enable one class to inherit from another class?
    A. inherits
    B. extends
    C. handItOverAndNobodyGetsHurt

  2. Why are compiled Java programs saved with the .classfile extension?
    A. Java’s developers think it’s a classy language.
    B. It’s a subtle tribute to the world’s teachers.
    C. Every Java program is a class.

  3. What are the two things that make up an object?
    A. Attributes and behavior
    B. Commands and data files
    C. Spit and vinegar


Answers



  1. B.Theextendsstatement is used because the subclass is an exten-
    sion of the attributes and behavior of the superclass and of any super-
    classes above that in the class hierarchy.

  2. C.Yo u r p r o g r a m s a r e a l way s m a d e u p o f a t l e a s t o n e m a i n c l a s s a n d
    any other classes that are needed.

  3. A.In a way,B also is true because commands are comparable to
    behavior,and data files are analogous to attributes.


Activities
If you don’t object,you can extendsyour knowledge of this hour’s topics with
the following activities:

. Create an AcousticModemclass with a speed of 300 and its own con-
nect()method.
. Add a disconnect()method to one of the classes in the Modemproj-
ect,deciding where it should go to support modem disconnection in
cable,DSL,and acoustic modems.


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