05 Objects and Classes
05 Objects and Classes
The objectives of this presentation are:
The following table shows where the members of the Alpha class are
visible for each of the access modifiers that can be applied to them.
Modifier Alpha Beta Alphasub Gamma
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N
}
Instance variables are encapsulated.
number = 12364
- no direct access from outside
overdraftLimit = 300 June 15,
the object
startDate 1994
owner
Each object has its own variables.
These variables are declared
within the class. Jupiter
0 null
Note: null means “refers
to no object”
Employee anEmployee;
[...]
if (anEmployee == null)
{
}
Employee anEmployee;
[...]
anEmployee
anotherEmployee Employee
objectReference.methodName(parameters);
[...]
if (aCar.calculateSpeed()>110)
{
System.out.println("You're Speeding!");
}
[...]
public BankAccount()
{
}
[...]
}
Java Dr. Ashraf Uddin 28
Constructors - Example
When an object is created (using new) the compiler
determines which constructor is to be invoked by the
parameters passed
Multiple constructors allows the class programmer to define many
different ways of creating an object.