I'm New to Java and I am following some instruction, However When I get to the Strings section
public class String {
public static void main(String[] args) {
java.lang.String name;
name = "luke";
System.out.println("Hello, " + name + "pleased to meet you");
}
}
But I Get
Error: Main method not found in class String, please define the main method as:
public static void main(String[] args)
If you insist on using String as your class name it should be:
public class String {
public static void main(java.lang.String[] args) {
java.lang.String name;
name = "luke";
System.out.println("Hello, " + name + "pleased to meet you");
}
}
I don't think it's particularly wise to try and re-use the names of classes defined in java.lang
though.
Since your class is named String, it is being inferred by the compiler as the argument type of your main method.
Try fully qualifying the argument type instead:
public static void main(java.lang.String[] args) {
...
Or better yet, rename your class to use and non-java.lang class name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With