$ 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
$ cat Const.java public class Const { String Const(String hello) { return hello; }
Share
What you’ve defined isn’t actually a constructor, but a method called
Const. If you changed your code to something like this, it would work:If no specific constructor is explicitly defined, the compiler automatically creates a no-argument constructor.