I am trying to compile the following code:
public class Test {
public static void main(String[] args) {
String final = new String("");
final = "sample";
System.out.println(final);
}
}
Apparently, the compiler shows me the following errors:
Test.java:5: error: not a statement
String final = new String("");
^
Test.java:5: error: ';' expected
String final = new String("");
^
Test.java:5: error: illegal start of type
String final = new String("");
^
Test.java:6: error: illegal start of type
final = "sample";
^
Test.java:7: error: illegal start of expression
System.out.println(final);
^
Test.java:7: error: illegal start of type
System.out.println(final);
^
I've tried replacing String final = new String("");
with String final;
but the compiler is still showing these errors. Any idea what might cause this?