Weiter Methoden zum Zugriff auf Objekteigenschaften: class Point extends Object { private double x; /* instance variable */ private double y; /* instance variable */ Point() { /* constructor to initialize to zero */ x = 0.0; y = 0.0; } /* constructor to initialize to specific value */ Point(double x, double y) { this.x = x; this.y = y; } public void setX(double x) { /* accessor method */ this.x = x; } public void setY(double y) { /* accessor method */ this.y = y; } public double getX() { /* accessor method */ return x; } public double getY() { /* accessor method */ return y; } } Damit sind dann Zugriffe auf Objekteigenschaften in der folgenden Weise möglich: Point myPoint; // declares a variable to refer // to a Point object myPoint = new Point(); // allocates an instance of a // Point object myPoint.setX(10.0); // sets the x variable via myPoint.setY(25.7); // the accessor method
Weiter Methoden zum Zugriff auf Objekteigenschaften:
class Point extends Object { private double x; /* instance variable */ private double y; /* instance variable */ Point() { /* constructor to initialize to zero */ x = 0.0; y = 0.0; } /* constructor to initialize to specific value */ Point(double x, double y) { this.x = x; this.y = y; } public void setX(double x) { /* accessor method */ this.x = x; } public void setY(double y) { /* accessor method */ this.y = y; } public double getX() { /* accessor method */ return x; } public double getY() { /* accessor method */ return y; } }
Damit sind dann Zugriffe auf Objekteigenschaften in der folgenden Weise möglich:
Point myPoint; // declares a variable to refer // to a Point object myPoint = new Point(); // allocates an instance of a // Point object myPoint.setX(10.0); // sets the x variable via myPoint.setY(25.7); // the accessor method
Point myPoint; // declares a variable to refer // to a Point object myPoint = new Point(); // allocates an instance of a // Point object
myPoint.setX(10.0); // sets the x variable via myPoint.setY(25.7); // the accessor method