Object constructor concept in Java | can we write a method name same as constructor name in class definition

Concept 1:  can we write a method same name as constructor in class definition.

Exp:     Yes we can write a method same name as constructor in java class definition.

Code :

package com.threadTest;

public class constructorTest {

    public void constructorTest()
    {
        System.out.println("Inside the constructor");
        return;
       
    }
public static void main(String[] args)
{
    constructorTest ct=new constructorTest();
}

}

Above code compile without Error





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.