Results 1 to 2 of 2
  1. #1
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default I have a problem with final

    Hi friends,
    I am new to this forum.
    I am learning java now.
    I have a problem in defining a constant using final .please help me.
    Java Code:
    class Testconst
    {
    public static void main(String args[])
    {
    static final double PI = 3.141592653589793;
    System.out.println("pi="+pi);
    //........
    //.......
    }
    }
    when i compiled this,i got an error like this
    illegal start of expression
    static final double PI = 3.141592653589793;

    Is there any mistake in my code ?
    please tell me.
    Thank u very much.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    C:\jexp>javac test.java
    exptest.java:5: illegal start of expression
            static final double PI = 3.141592653589793;
            ^
    1 error
    Try either
    Java Code:
    public class Test {
        static final double PI = 3.141592653589793;
    
        public static void main(String[] args) {
            System.out.println("PI = " + PI);
        }
    }
    or
    Java Code:
    public class Test {
        public static void main(String[] args) {
            final double PI = 3.141592653589793;
            System.out.println("PI = " + PI);
        }
    }

Similar Threads

  1. UJO Framework 0.73.final
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-15-2008, 06:53 PM
  2. UJO Framework 0.72.final
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-17-2008, 08:28 PM
  3. problem with final
    By sireesha in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 01:31 AM
  4. PLz i really need help on this final thing
    By jason27131 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 02:31 AM
  5. Poi 3.0-final
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-22-2007, 07:05 AM

Posting Permissions

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