Accessors and Mutators
public class Rectangle Data field, attributes,
{ data members
private double width;
private double length;
public void setWidth(double w)
{ width = w;
}
Setter , Mutator
public void setLength(double len)
{ length = len;
}
public double getWidth()
{ return width;
}
public double getLength() Getter, Accessor
{ return length;
}
public double getArea()
{ return length * width;
}
}
Objects and Classes
This expression creates a
Example: Scanner object in memory.
Scanner Input= new Scanner([Link]);
The object's memory address
is assigned to the Input
variable.
Input Scanner
variable object
Uninitialized Local Reference Variables
• Reference variables can be declared without being initialized.
Rectangle box;
• This statement does not create a Rectangle object, so it is an uninitialized local
reference variable.
• A local reference variable must reference an object before it can be used, otherwise a
compiler error will occur.
box = new Rectangle();
Box Rectangle
variable object
More Examples