Is it true that constructor returns an object?

Avinash Kumar :
class Test{
  public Test(){
    System.out.println("I am here");
    return;// not getting error
  }

  public static void main(String[] args){
    Test test = new Test();
  }
}

I am java beginner. My tutor told me that constructor returns an object and showed me the above example. is it really happening because method is not returning any value but the return;is not getting an error.

Dawood ibn Kareem :

No, a constructor initialises an object that's already been created. It doesn't return an object. Your tutor is wrong.

You don't need to write return; inside a constructor, unless you're returning before the end of the code.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=472785&siteId=1