Java: How can a constructor return a value?

Posted by HH on Stack Overflow See other posts from Stack Overflow or by HH
Published on 2010-04-04T11:45:45Z Indexed on 2010/04/04 11:53 UTC
Read the original article Hit count: 263

$ cat Const.java 
public class Const {
    String Const(String hello) {
        return hello; 
 }
 public static void main(String[] args) {
     System.out.println(new Const("Hello!"));
 }
}
$ javac Const.java 
Const.java:7: cannot find symbol
symbol  : constructor Const(java.lang.String)
location: class Const
  System.out.println(new Const("Hello!"));
                     ^
1 error

© Stack Overflow or respective owner

Related posts about java

Related posts about constructor