PPT Slide
Classes can have methods that operate on the fields of the class
public class Coordinate {
public int x;
public int y;
// Set field x to p*p
public void setX(int p) {
x= p*p;
}
// Set field y to q
public void setY(int q) {
y= q;
}
// Return the sum of the squares of the fields
public int sumSquares() {
return x*x + y*y;
}
}
Previous slide
Next slide
Back to first slide
View graphic version