---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 18 Edition"
java_version: 18
chapter: "Chapter 8. Classes"
section: "8.8.1"
heading: "8.8.1. Formal Parameters"
parent: "8.8. Constructor Declarations"
source: https://docs.oracle.com/javase/specs/jls/se18/html/jls-8.html#jls-8.8.1
id: "8.8.1"
url: https://jvm.obfuscated.software/jls/se18/8.8.1.html
raw: https://jvm.obfuscated.software/jls/se18/8.8.1.md
---

# 8.8.1. Formal Parameters

The formal parameters of a constructor are identical in syntax and semantics to those of a method ([§8.4.1](8.4.1.md)).

If the last formal parameter of a constructor is a variable arity parameter, the constructor is a *variable arity constructor*. Otherwise, it is a *fixed arity constructor*.

The constructor of a non-`private` inner member class implicitly declares, as the first formal parameter, a variable representing the immediately enclosing instance of the class ([§15.9.2](15.9.2.md), [§15.9.3](15.9.3.md)).

The rationale for why only this kind of class has an implicitly declared constructor parameter is subtle. The following explanation may be helpful:

1. In a class instance creation expression for a non-`private` inner member class, [§15.9.2](15.9.2.md) specifies the immediately enclosing instance of the member class. The member class may have been emitted by a compiler which is different than the compiler of the class instance creation expression. Therefore, there must be a standard way for the compiler of the creation expression to pass a reference (representing the immediately enclosing instance) to the member class's constructor. Consequently, the Java programming language deems in this section that a non-`private` inner member class's constructor implicitly declares an initial parameter for the immediately enclosing instance. [§15.9.3](15.9.3.md) specifies that the instance is passed to the constructor.
2. In a class instance creation expression for an inner local class or an anonymous class (not in a static context), [§15.9.2](15.9.2.md) specifies the immediately enclosing instance of the local/anonymous class. The local/anonymous class is necessarily emitted by the same compiler as the class instance creation expression. That compiler can represent the immediately enclosing instance how ever it wishes. There is no need for the Java programming language to implicitly declare a parameter in the local/anonymous class's constructor.
3. In a class instance creation expression for an anonymous class, and where the anonymous class's superclass is an inner class (not in a static context), [§15.9.2](15.9.2.md) specifies the anonymous class's immediately enclosing instance with respect to the superclass. This instance must be transmitted from the anonymous class to its superclass, where it will serve as the immediately enclosing instance. Since the superclass may have been emitted by a compiler which is different than the compiler of the class instance creation expression, it is necessary to transmit the instance in a standard way, by passing it as the first argument to the superclass's constructor. Note that the anonymous class itself is necessarily emitted by the same compiler as the class instance creation expression, so it would be possible for the compiler to transmit the immediately enclosing instance with respect to the superclass to the anonymous class how ever it wishes, before the anonymous class passes the instance to the superclass's constructor. However, for consistency, the Java programming language deems in [§15.9.5.1](15.9.5.1.md) that, in some circumstances, an anonymous class's constructor implicitly declares an initial parameter for the immediately enclosing instance with respect to the superclass.

The fact that a non-`private` inner member class may be accessed by a different compiler than compiled it, whereas an inner local class or an anonymous class is always accessed by the same compiler that compiled it, explains why the binary name of a non-`private` inner member class is defined to be predictable but the binary name of an inner local class or an anonymous class is not ([§13.1](13.1.md)).
