Home  >  Article  >  Java  >  Java constructors return a value, but what do they return?

Java constructors return a value, but what do they return?

王林
王林forward
2023-08-25 15:33:101073browse

Java constructors return a value, but what do they return?

No. Java constructors cannot return values. If needed, just create a method that calls the required constructor and returns the required value. See example below.

public class Tester {
   public Tester(){}
   public static Tester getInstance(){
      Tester tester = new Tester();
       return tester;
   }
}

The above is the detailed content of Java constructors return a value, but what do they return?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete