Beruflich Dokumente
Kultur Dokumente
OOPS
OBJECT ORIENTED
PROGRAMMING
An object is an instance if a class. You can create many instances EXAMPLE OF AN OBJECTs CLASS
of a class.
e.g., e.g.,
//Retrieves the current radius for this circle //Set a new radius value for this circle
public double getRadius() public void setRadius( double newRad)
{ {
return radius; radius=newRad;
} }
4/5/2017
SHOWN ON ECLIPSE }
ARRAY OF OBJECTS
DEMO THE USE OF AN ARRAY OF
If we needed to create more than one object, we could use
an Array. OBJECTs
An array of objects is actually an array of reference
variables.
The toString() method returns a string representation of the You can use keyword "this" to refer to this instance inside a
object. class definition
Usually you should include a toString method so that it One common use of the this keyword is reference a classs
returns a digestible string representation of the object. hidden data fields.
public String toString() Another common use of the this keyword to enable a
{
constructor to invoke another constructor of the same
return "radius " + radius ;
} class.
public double getArea() { User of the class does not need to know how the class is implemented.
return this.radius * this.radius * Math.PI; The detail of implementation is encapsulated and hidden from the user.
}
}
4/5/2017
ADDITIONAL RESOURCES