Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2010
    Posts
    18
    Rep Power
    0

    Default Error while compiling

    class dosomething{
    int x=3;
    String name="vibavi";
    x=x*17;
    public static void main(String[]args){

    System.out.print("x is"+x);
    double d=Math.random();

    }//end of main method
    } //end of class

    i tried this but i got an error
    identifier expected
    cant i creates variables in outside main methord?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,039
    Rep Power
    20

    Default

    You can declare attributes, yes, but you can't have code like this:
    x=x*17;

  3. #3
    Join Date
    Nov 2010
    Posts
    18
    Rep Power
    0

    Default

    whats wrong with
    x=x+17;?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,039
    Rep Power
    20

    Default

    It's not inside a method, or executable block (ie curly braces).
    You can't have executable code outside of a block.
    You can only have declarations.

Similar Threads

  1. Compiling error
    By robbierut in forum Java Applets
    Replies: 4
    Last Post: 11-24-2010, 05:00 PM
  2. Having error while compiling
    By Kodeee in forum New To Java
    Replies: 12
    Last Post: 03-17-2009, 11:08 AM
  3. Compiling error
    By lawksalih in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 07:26 PM
  4. Error during compiling
    By boy22 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 02:42 AM
  5. Error while compiling
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2007, 11:37 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
  •