Results 1 to 3 of 3
  1. #1
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Question Illegal start of expression

    Hi to all,
    Hope everyone will be fine.What's wrong with the code why it is saying illegal start of expression

    Java Code:
    package staticandnonstatic;
    
    public class Main {
    
        static int num =4;
       
        public static void main(String[] args) {
            
           public void test(){
              int mynum = num; 
           }  
        }
    }
    Also with this code show illegal start of expression, why
    Java Code:
    package staticandnonstatic;
    
    
    public class Main {
    
       public static void main(String[] args) {
            
           static int num =4;
            
            public void test(){
              int mynum = num; 
            }  
        }
    }
    Thanks in advance

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You're nesting a method inside of another method which you cannot do in Java. Get the test method outside of the main method.

  3. #3
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

Similar Threads

  1. Illegal Start of an Expression
    By ddatta8 in forum New To Java
    Replies: 3
    Last Post: 12-20-2008, 09:40 PM
  2. illegal start of expression
    By razmyasdfg in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-27-2008, 11:44 PM
  3. Illegal Start of an Expression
    By David55 in forum CLDC and MIDP
    Replies: 8
    Last Post: 11-02-2007, 10:11 PM
  4. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 06:09 PM
  5. Illegal Start of an Expression
    By David55 in forum CLDC and MIDP
    Replies: 0
    Last Post: 04-20-2007, 06:59 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
  •