Thursday, June 01, 2006

super() method

The first line of every constructor must call another constructor. If you do not explicitly call another constructor with this() or super(), he compiler always makes super() with no parameters the first line of a constructor.

public ClassName()
{
System.out.println(“Hello!”);
}
public ClassName()
{
super();
System.out.println(“Hello!”);
}

This happens because it is essential that your superclass be initialized before your subclass.

0 Comments:

Post a Comment

<< Home