"illegal modifier for parameter sum; only final is permitted
Code :
public class AddTenIntegers
{
public static void main (String[] args)
{
private int sum; ILLEGAL MODIFIER FOR PARAMETER SUM; ONLY FINAL IS PERMITTED
private int i; ILLEGAL MODIFIER FOR PARAMETER I; ONLY FINAL IS PERMITTED
sum = 0;
i = 0;
while (i >= 10)
{
sum = sum + i;
i++;
}
}
}
what does that error mean?
Re: "illegal modifier for parameter sum; only final is permitted
The modifiers private, protected, and public cannot be used on variables inside of a method. This is because you can only have local variables inside of methods.
Java is simply telling you that the only modifier allowed at that time is the final keyword.
Re: "illegal modifier for parameter sum; only final is permitted
The key words private, protected, and public can limit methods, member variables of the class. But they can't limit the local
variables of the method. Both of the variables in main are local variables.
Re: "illegal modifier for parameter sum; only final is permitted
Hi
Access modifiers cannot be used with local variables.So,you ca not use private access modifier in case of local variables.