Content deleted Content added
m →Java: indent, <ref> |
|||
Line 116:
# Initialize member variables to the specified values.
# Executes the body of the constructor.
Java permit users to call one constructor in another constructor using <code>this()</code> keyword.
But <code>this()</code> must be first statement.
<source lang="java">
class Example
{
Example() //non-parameterized constructor
{
this(1); //calling of constructor
System.out.println("0-arg-cons");
}
Example(int a) //parameterized constructor
{
System.out.println("1-arg-cons");
}
public static void main(String[] args)
{
Example e= new Example();
}
</source>
Java provides access to the [[superclass (computer science)|superclass's]] constructor through the <code>super</code> keyword.
|