This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
java:objects [2016/02/18 13:58] doufexi fixed constructor and calls, added observation re: field initialization in constructor, added toc link, fixed minor typos |
java:objects [2016/02/26 11:15] 127.0.0.1 external edit |
||
---|---|---|---|
Line 36: | Line 36: | ||
public class Rectangle { | public class Rectangle { | ||
| | ||
- | // the Rectangle class has 3 fields | + | // fields |
private int width; | private int width; | ||
private int height; | private int height; | ||
private Point origin; | private Point origin; | ||
| | ||
- | // the Rectangle class has one constructor | + | // constructors |
public Rectangle(int initWidth, int initHeight, Point initOrigin) { | public Rectangle(int initWidth, int initHeight, Point initOrigin) { | ||
width = initWidth; | width = initWidth; | ||
Line 54: | Line 54: | ||
} | } | ||
| | ||
- | // the Rectangle class has 3 methods | + | // methods |
public void setWidth(int newWidth ) { | public void setWidth(int newWidth ) { | ||
width = newWidth; | width = newWidth; |