The Member Access Separator .

class Car {

  String licensePlate; // e.g. "New York 543 A23"
  double speed;        // in kilometers per hour
  double maxSpeed;     // in kilometers per hour


Once you've constructed a car, you want to do something with it. To access the fields of the car you use the . separator. The Car class has three fields

Therefore if c is a Car object, c has three fields as well:

You use these just like you'd use any other variables of the same type. For instance:

    Car c = new Car();
    c.licensePlate = "New York A45 636";
    c.speed = 70.0;
    c.maxSpeed = 123.45;
    System.out.println(c.licensePlate + " is moving at " + c.speed + 
      "kilometers per hour.");

The . separator selects a specific member of a Car object by name.

Previous | Next | Top | Cafe au Lait

Copyright 1997-1999 Elliotte Rusty Harold
Last Modified October 1, 1999