Beruflich Dokumente
Kultur Dokumente
UML Basics
The top section gives the class name, the middle section describes
the fields, and the bottom section describes the methods. The
middle and bottom sections are optional, but the top section is
required.
The top section is required. It gives the objects name and its
defining class. The second section is optional; it indicates the
Public
Private
Final
Protected
Static
Default
Good!
What is this Modifier?
-radius: double
Public
Private
Final
Protected
Static
Default
Good!
What is this one?
+ numberOfObjects(): int
Public
Private
Final
Protected
Static
Default
Good!
What is this one?
# aMethod(): void
Public
Private
Final
Protected
Static
Default
see
see
see
class Rectangle
Rectangle class
class Rectangle
{
// Data members
private double width = 1, height = 1;
private static String color = "yellow";
It has two
private or
local
variables,
and a static
or global
variable that
is shared.
Rectangle class
// Constructor
public Rectangle()
{
}
The default
constructor (with no
parameters) - it will
use the initialized
values for height,
width, and color.
Rectangle class
// Constructor
public Rectangle(double width, double height)
{
this.width = width
The Rectangle
this.height = height;
}
constructor needs
two
doubles.
If you wish to use the
same name in the
parameters (formal and
actual) you use this.
Rectangle class
In order to access or
make changes to private
variables, you need sets
and gets.
(Accessors and Mutators)
Rectangle class
This is to access a
Rectangle objects height
and width after it is
constructed.
Rectangle class
Rectangle class
Rectangle class
class Rectangle {
// Data members
private double width = 1, height = 1;
private static String color = "yellow";
// Constructor
public Rectangle() {
}
// Constructor
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
TestRectangle class
TestRectangle class
TestRectangle class
TestRectangle class
TestRectangle class
TestRectangle class
TestRectangle class
myRect3.setColor("red");
is "
TestRectangle class