previous | start | next

Syntax 2.7 : Constructor Implementation

 
accessSpecifier class ClassName
{
...
accessSpecifier ClassName(parameterType
parameterName
...)
{
constructor implementation
}
...
}

Example:

 
public class Greeter
{
...
public Greeter(String aName)
{
name = aName;
}
...
}

Purpose:

To define the behavior of a constructor, which is used to initialize the instance fields of newly created objects



previous | start | next