Constructors

A constructor is a special method, named after the class and with no return type, called by new to initialize the object. You can define several (overloading) and chain them with this(...). Without an explicit constructor, Java provides a default one with no parameters.

Example

class Point {
    int x, y;
    Point(int x, int y) { this.x = x; this.y = y; }
}

Related concepts

The whole glossary