Initialization of structures without any constructor in Java
Rectangle rect = new Rectangle();
Size size = new Size();
size.width = 10;
size.height = 10;
rect.size = size;
Point point = new Point();
point.left = 5;
point.top = 5;
rect.point = point;
//The Java language has no structures
class Size {
public int width, height;
}
class Point {
public int top, left;
}
class Rectangle {
public Size size;
public Point point;
}
- Log in to post comments