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
  • licensePlate
  • speed
  • maxSpeed
Therefore if c is a Car object, c has three fields as well:
  • c.licensePlate
  • c.speed
  • c.maxSpeed
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.

List | Previous | Next