Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: "illegal modifier for parameter sum; only final is permitted

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Location
    norcross, ga
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default "illegal modifier for parameter sum; only final is permitted

    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?
    Last edited by helloworld922; January 29th, 2010 at 06:26 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. How do you pass an Array as a Parameter?
    By Arius in forum Java Theory & Questions
    Replies: 1
    Last Post: January 23rd, 2010, 09:36 PM
  2. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  3. Illegal Start of Expression Error. Any help is appreciated.
    By SKhoujinian91 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 8th, 2009, 12:57 AM
  4. Passing objects as a constructor parameter
    By derky in forum Object Oriented Programming
    Replies: 2
    Last Post: October 27th, 2009, 04:31 AM
  5. final class, final <variable> or <data member>
    By chronoz13 in forum Object Oriented Programming
    Replies: 9
    Last Post: September 20th, 2009, 08:19 AM