Java Reference
In-Depth Information
Self-review exercises
SR1 .
A definition of a class Circle goes in a file named _______________.
SR2 .
A class definition describes the contents of _____________________ .
SR3 .
The syntax of a class definition is: ____________________________.
SR4 . To import the classes of package javax.swing , place this statement
before the class definition: _____________________________.
SR5 . State the principle of information hiding. What keyword is used to hide
fields or instance methods of a class?
SR6 . State the general inside-out rule in programming languages. How does it
apply to method bodies?
SR7 .
A getter method is to used to ________________________.
SR8 .
A constructor is called to _______________________________.
SR9 . How do you write the constructor call C(7, 60); from another construc-
tor in class C , and where do you put the call?
SR10 . The purpose of function toString in a class C is to ______________.
SR11 . Obtain file from the bottom of lesson page 3-3 of
ProgramLive . Place it in a folder by itself. Open it in DrJava and compile it. In
the Interactions pane, create an instance or two of the class and experiment with
calls to its methods.
Type the second constructor for it, the one just before Sec. 3.1.4. Compile
and experiment with creating instances using calls to this constructor.
SR12 Write a class that represents a point in the (x,y) plane. What fields does
it have? Should they be private or public? What methods will it have? Type your
class into DrJava and test all the methods.
Answer to Self-review exercises
SR1 . .
SR2 .
The folders (instances, or objects) of the class.
SR3 . public class class-name {
declarations of variables and methods
SR4 . Put this statement before the class definition: import javax.swing.*;
SR5 . Make available to someone only what they need to know. Keyword pri-
vate hides fields or instance methods of a class.
Search WWH ::

Custom Search