6 Replies Latest reply: Apr 13, 2013 1:56 AM by 1002857 RSS

    Illegal start of expression error

    1002412
      class Test1
           {
           public static void main(String args[])
                {
                void show()
                     {
                     System.out.print("its working");
                     }
                show();
                }
           }
      When i compile this program i find the error illegal start of expression
      ^void show
      Test1.java5 ';' is expected
        • 1. Re: Illegal start of expression error
          Kayaman
          You can't declare a method inside another method. Now your show() is inside main(), which just doesn't work. Put them side by side inside the class.
          • 2. Re: Illegal start of expression error
            gimbal2
            When i compile this program i find the error illegal start of expression
            Just a tip: you're going to take decades learning Java if you have to go to a forum for every little thing you run into and wait for an answer: you'll be running into hundreds of errors and problems before you can call yourself a novice. Get a good book and follow its guidance carefully in stead.
            • 3. Re: Illegal start of expression error
              1002412
              Thank u very much sir for your kind advice i am just a student i m following the book "the complete reference java 7th edition" by Herbt Schildt do u have any other book in mind please suggest me i am not so much strong in English so the book should use simple words plz mail me my id is XXXXXXXXX

              Mod: email removed

              Edited by: PhHein on 11.04.2013 13:33
              • 4. Re: Illegal start of expression error
                PhHein
                Don't draw discussion away from the forums by posting your email.

                I've never seen anyone being happy with any Schildt book. Head first Java seems to be popular. Go to a library or book store and glance through a couple of books to find a suitable one for you.
                • 5. Re: Illegal start of expression error
                  gimbal2
                  Or check the amazon user reviews. They have never steered me wrong. You need to find a book that matches your taste and needs, its a personal thing that cannot really be subject to a recommendation by people who don't know you.
                  • 6. you can create class any where in java except Main method try this program.
                    1002857
                    public class demomanav {

                    interface m1 {
                    public void greet();
                    public void greetSomeone(String someone);
                    }

                    public void sayHello()
                    {

                    class k1 implements m1
                         {
                    String name = "world";
                    public void greet()
                         {
                    greetSomeone("world");
                    }
                    public void greetSomeone(String someone)
                              {
                    name = someone;
                    System.out.println("Hello " + name);
                    }
                    }
                    k1 obj = new k1();
                    obj.greet();
                    obj.greetSomeone("manav");
                    }
                    public static void main(String []p)
                    {
                    demomanav obj= new demomanav();
                    obj.sayHello();
                    }
                    }
                    you can create class any where in java except Main method. try above program.

                    Edited by: 999854 on Apr 12, 2013 11:55 PM