Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2016
    Posts
    41
    Rep Power
    0

    Default Illegal modifier for parameter [insert field name]; only final is permitted

    I have a pic attached which shows the tabs I am using in Eclipse. I am declaring a field named 'server' which is of the class 'MailServer.' Then I am trying to create an instance of 'MailServer' and assigning it to the field called 'server.'

    What is causing this error?
    Attached Thumbnails Attached Thumbnails Illegal modifier for parameter [insert field name]; only final is permitted-illegal-modifier-error.jpg   Illegal modifier for parameter [insert field name]; only final is permitted-error-console-window.jpg   Illegal modifier for parameter [insert field name]; only final is permitted-error-when-running.jpg  
    Last edited by allDogsAreGood; 08-31-2018 at 02:04 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,217
    Rep Power
    12

    Default Re: Illegal modifier for parameter [insert field name]; only final is permitted

    Since you declared the variable server inside of main (which is a method), it cannot be declared private. Variables inside of methods are inherently local in scope and not accessible outside of that method. the classifier private is only for class variables. If you want to ensure that a variable can only be set a single time, you can declare it final.

    e.g.

    Java Code:
    final MailServer server = new MailServer();
    
    //or
    
    final MailServer server;
    server = new MailServer();
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Join Date
    Oct 2016
    Posts
    41
    Rep Power
    0

    Default Re: Illegal modifier for parameter [insert field name]; only final is permitted

    Thank you. This makes sense.

Similar Threads

  1. Access Modifier 'final'
    By Ruben in forum New To Java
    Replies: 12
    Last Post: 06-25-2012, 07:52 AM
  2. Passing final parameter from a class
    By ianyappy in forum New To Java
    Replies: 8
    Last Post: 12-02-2010, 07:06 PM
  3. Synchronization on non-final field
    By newbiejava in forum New To Java
    Replies: 20
    Last Post: 08-10-2010, 09:58 AM
  4. Replies: 0
    Last Post: 02-18-2009, 05:20 AM
  5. static final field
    By techie.it19 in forum New To Java
    Replies: 3
    Last Post: 10-16-2008, 04:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •