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

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

王林
Release: 2023-08-25 15:33:10
forward
1117 people have browsed it

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;
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template