Calling this(...) as the first statement of a constructor delegates to another constructor of the same class, so shared setup lives in one place instead of being copied.
class Point {
final int x, y;
Point() {
this(0, 0);
System.out.println("no-arg constructor finished");
}
Point(int x, int y) {
this.x = x;
this.y = y;
System.out.println("full constructor: (" + x + ", " + y + ")");
}
}
Point p = new Point();
System.out.println("p = (" + p.x + ", " + p.y + ")");
full constructor: (0, 0)
no-arg constructor finished
p = (0, 0)
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27