Tuesday, March 3, 2009

Constructor Example

public class constructor_ex {
public constructor_ex()
{
System.out.print("Constructor example");
}
public static void main(String args[])
{
constructor_ex obj=new constructor_ex();
}
}
/*constructor is a method in a class ,that has same name as that of a class.
* constructor don't have return type ,not even void.
* They automatically intialize objects with default values , when they are created.
* They are invoked using new operator .
* They can't be inherited .
* "This" and "super" can be used .
*/

No comments:

Post a Comment