Constructor (object-oriented programming): Difference between revisions

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. Click hare to get details on Constructor in java <ref>[https://ranjeetkumarmaurya.wordpress.com/2017/02/06/constructor-in-java/ Details on Constructor in java]</ref>
 
<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.