Constructor :: It very common requirement to initialize an object immediately after creation. We can define non-static methods for this purpose but they have to be invoked explicitly. Java has a solution for this requirement. Java allows objects to initialize themselves when they are created using constructors.
PROGRAM
class Sample
{
Sample(
)
{
System.out.println("Constructor
called");
}
}
class ConsDemo
{
public
static void main(String args[ ])
{
Sample
ob=new Sample( );
}
}
Comments
Post a Comment