Language syntax

Java Constructor declaration

Initializes an instance; has no return type, and declaring one suppresses the implicit default constructor.

Formal Syntax & Structure

java syntaxjava
ClassName(parameters) { /* body */ }

Working Example

Example Snippetjava
class Book {    private String title;    Book(String title) { this.title = title; }    String title() { return title; }}public class Main {    public static void main(String[] args) {        Book book = new Book("Atlas");        System.out.println(book.title());    }}
Java Reference