Using a final keyword in the main method parameter solves the problem. Why is there no compiler error or exception since I modified Java's standard main method?
Now let's see if I can code:
When you execute the programme using the above coding, pass an argument as:
The output of my programme is
I have yet to receive a response.
Now repeat the process with the final keyword.
It throws an error saying that the final parameter, args, cannot be assigned.
Because I am now assigning str to args.
As I am following this source https://www.scaler.com/topics/java/f...yword-in-java/, this indicates I have made a significant difference by include the final keyword in the argument and making it constant in the main method. I'm updating the primary method's signature. So, why am I not receiving any compilation or runtime errors?
Code:
public class bytes {
public static void main(final String... args) {
System.out.println("Hi");
}
}
Code:
public class bytes {
public static void main (String... args) {
String[] str = {"I ", "haven't ", "received ", "my ", "answer." };
args[0] = "hi";
System.out.println(args[0]);
args =str;
for(int i=0; i<args.length; i++) {
System.out.print(args[i]);
}
}
}
Code:
javac bytes Nisrin
Code:
hi
Now repeat the process with the final keyword.
Code:
public class bytes {
public static void main (final String... args) {
String[] str = {"I ", "haven't ", "received ", "my ", "answer." };
args[0] = "hi";
System.out.println(args[0]);
args =str;
for(int i=0; i<args.length; i++) {
System.out.print(args[i]);
}
}
}
Because I am now assigning str to args.
As I am following this source https://www.scaler.com/topics/java/f...yword-in-java/, this indicates I have made a significant difference by include the final keyword in the argument and making it constant in the main method. I'm updating the primary method's signature. So, why am I not receiving any compilation or runtime errors?