Constructor is the object initialisation process during the execution of program.
Rules-
1. Constructor has the same name as the class name.
2. Constructor has no return type.
3. Constructer doesn't use dot operator to access.
4. Constructor is always public.
public class Test
{
public Test() //Constructor
{
System.out.println("This is Constructor");
}
public static void main()
{
Test t1 = new Test(); //Constructor will be called from here
}
}
Comments
Post a Comment