What's wrong with the below Code
public static void main(String[] args){
public static final String Name = "Robin Wilson";
}
String Reference Name shows Compilation Error - Java Error - Illegal Modifier for Parameter Name - Only final Permitted
Am okay with the below given suggestions, but I want to understand why its not permitted, though both are static?
You can't declare this inside
main
, put it outside the method, you want it as a [class member]:Otherwise(I don't think this is what you want) just remove
public static
from there and simply write:Static declaration of a component makes in available on a class level. Declaring component in a method makes in available in method's stack memory hence can only be accessed through an object. Static belongs to the whole class. Therefore their is no point in declaring a variable static. You'll even get the compile time error if you try to do so. Final keyword has nothing related to memory.