## Constructor is block of code which is executed at the time of object creation. But other than getting called, constructor is entirely different than methods and has some specific properties like name of constructor must be same as name of class. Constructor also can not have any return type.
Example::
public class Hello{
String s ="WORLD";
Hello() //constructor
{
System.out.println(s);
}
public static void main(String args[])
{
Hello object = new Hello(); //Hello() called constructor
}
}
No comments:
Post a Comment