Java Reference
In-Depth Information
The heading of the default constructor is:
public Clock()
The heading of the constructor with parameters is:
public Clock( int hours, int minutes, int seconds)
The definition of the class Clock has 16 members: 11 methods to implement the 11
operations, 2 constructors, and 3 instance variables to store the hours, minutes, and
seconds.
If you do not include any constructor in a class, then Java automatically provides the
default constructor. Therefore, when you create an object, the instance variables are
initialized to their default values. For example, int variables are initialized to 0 . If you
provide at least one constructor and do not include the default constructor, then Java
will not automatically provide the default constructor. Generally, if a class includes
constructors, you should also include the default constructor.
Unified Modeling Language Class Diagrams
A class and its members can be described graphically using Unified Modeling Language
(UML) notation. For example, Figure 8-1 shows the UML diagram of the class Clock .
Also, what appears in the figure is called the UML class diagram of the class.
Clock
-hr: int
-min: int
-sec: int
+Clock()
+Clock( int , int , int )
+setTime( int , int , int ): void
+getHours(): int
+getMinutes(): int
+getSeconds(): int
+printTime(): void
+incrementSeconds(): int
+incrementMinutes(): int
+incrementHours(): int
+equals(Clock): boolean
+makeCopy(Clock): void
+getCopy(): Clock
FIGURE 8-1 UML class diagram of the class clock
 
 
Search WWH ::




Custom Search