You are here :

Sub nodes

Recent changes
Site plan

Constructors are special methods that are called when instantiating a class. The purpose of a constructor is to initialise the class.

Constructors have a special name : constructor ! They have no result. A constructor can be public/private/protected/package.

Syntax :

 [public | protected | private] constructor(ArgumentListDeclaration) {
   // code

Example :

 public class SomeClass {
   public constructor() {
     // put here initialisation of your class
   public constructor(int i) {
     // put here initialisation of your class based on the value of i

Default constructor

If you don't provide constructors, a default constructor is created for you. A default constructor takes no argument. A default constructor calls

If you provide a custom constructor then no default constructor will be created.

Propulsed by Wiclear