Structures constructors (initializers) in Java
Forums:
//In Java there are no structures
class Point {
public int x, y;
public Point() { }
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
Point p1 = new Point(1, 2);
//p1.x is 1 and p1.y is 2
Point p2 = new Point();
//p2.x is 0 and p2.y is 0
- Log in to post comments