Java Objects
Objects are containers around aggregates of primitive types, arrays, and other objects
Properties of Classes
- All Java code is contained within objects
- Objects are passed to methods by reference
- Definition, declaration, and creation of objects are distinct
- Instances of objects are created with
new and have a value of null
- Objects have four forms: the class, the abstract class, the inner class, and the interface
class Circle { // object definition
static double pi = 3.141592; // class variable
double radius; // instance variable
public Circle(double r) { // constructor method
radius = r;
}
public double circumference() { return 2*pi*radius; }
public double area() { return pi*radius*radius; }
}
Circle c; // object declaration
c = new Circle(4.0); // object creation
double a = c.area();
|