Methods

 

 

Methods say what an object does.

 

class TwoDPoint {

    double x;
    double y;
    
    void print() {
      System.out.println(this.x + "," + this.y);
    }
    
  }
  
}

Notice that you use the Java keyword this to reference a field from inside the same class.

 

TwoDPoint origin = new TwoDPoint();
origin.x = 0.0;
origin.y = 0.0;
origin.print();

noun-verb instead of verb-noun; that is subject-verb instead of verb-direct object.

subject-verb-direct object(s) is also possible.

 

 

List | Previous | Next