Java Error - Illegal Modifier for Parameter - Only final Permitted

前端 未结 8 718
既然无缘
既然无缘 2020-12-03 01:32

What\'s wrong with the below Code

public static void main(String[] args){
        public static final String Name = \"Robin Wilson\";
    }

相关标签:
8条回答
  • 2020-12-03 02:31

    as you are Declaring the String variable as public static final String Name = "Robin Wilson";

    According to java rules, This String name is Local variable as you are declaring it in Main method. So only final is permitted here. you can define it as ** final String name="Robin Wilson";** in main method. for Local variables only final is permitted.

    0 讨论(0)
  • 2020-12-03 02:32

    you can not use public static modifier for a local variable. Do any of the followings

    public static void main(String[] args){
            final String Name = "Robin Wilson";
        }
    

    or declare it as a member variable

    public static final String Name = "Robin Wilson";
    
    public static void main(String[] args){
    
     }
    

    Remember that the final is the only modifer of the local variables

    0 讨论(0)
提交回复
热议问题