► |  | How to Design Classes Languages

1 | Professor J Beginner
2 | Professor J Intermediate
3 | Professor J Intermediate + Access
4 | Professor J Advanced
| Index

▼ | 4 | Professor J Advanced

4.1 | package
4.2 | import
4.3 | class
4.4 | interface
4.5 | Modifiers
4.6 | Field
4.7 | Method
4.8 | Constructor
4.9 | Statement
4.10 | Array Init
4.11 | Expression

Version: 4.1.4
top← prev up next →

#### 4.8`` Constructor

Id (Type Id ,...) {Statement ...}

Creates a constructor that is used in creating an instance of a class (called an object). The arguments given when creating an instance must be of the same type, and in the same order, as that specified by the constructor. The statements are executed in sequence in intializing the object. If the parent of the current class contains a constructor, that expects parameters, then the first statement in the constructor must be a super call.

Multiple constructors can appear in a class body, provided that for each constructor the type of arguments or the number of arguments is unique. Each constructor may set its own access. A constructor in the same class can be called using a this call. This must be the first statement.

top← prev up next →