Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: i have writtena simple java program with one method but method is not executing ....

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default i have writtena simple java program with one method but method is not executing ....

    import java.io.*;
    class method
    {
    public static void main(String args[])
    {
    System.out.println("hey ho");

    void clear()
    {
    System.out.println("Finally its working ");
    }

    }

    }


  2. #2
    Junior Member
    Join Date
    Dec 2013
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: i have writtena simple java program with one method but method is not executing ....

    My question: Are there any lines of this code which seem unnecessary?

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: i have writtena simple java program with one method but method is not executing ....

    Welcome to the forum! Please read this topic to learn how to post code correctly and other info useful to newcomers.

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i have writtena simple java program with one method but method is not executing ....

    when i run dis code method part shows errors
    the unnecessary line(println before method) u r referring is just to check if dere is any other problem ...... do u know wen does this happens ...

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: i have writtena simple java program with one method but method is not executing ....

    shows errors
    Please copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: i have writtena simple java program with one method but method is not executing ....

    import java.io.*;
    class method {
        public static void main(String args[]) {
            System.out.println("hey ho");
            void clear() {
                System.out.println("Finally its working ");
            }
        }
    }

    The 'main' is just a method, just like your 'clear' method. You need a main method so java knows where to start executing your application.

    So what you are trying to do now is placing a method (clear) in another method (main) which isn't possible.

    What you could do is call the 'clear' method from the main method, like this:
    import java.io.*;
    class method {
        public static void main(String args[]) {
            System.out.println("hey ho");
            clear();
        }
        void clear() {
            System.out.println("Finally its working ");
        }
    }

    You don't have to import java.io.* btw

  7. #7
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: i have writtena simple java program with one method but method is not executing ....

    yaa ryt thnx for the important tip .... but a small correction non static method can't be called with static context so either call them with a object or use it as a static method .....
    anyways than a ton was stuck on this for quite a long tym



    class method
    {
    public static void main(String fdff[])
    {
    System.out.println("hey ho");
    clear();
    }
    public static void clear() //static method
    {
    System.out.println("Finally its working ");
    }
    }

Similar Threads

  1. [SOLVED] How to create a Java generic method, similar to a C++ template method?
    By Sharmeen in forum Object Oriented Programming
    Replies: 3
    Last Post: October 18th, 2012, 02:33 AM
  2. Need to write a public instance method for a simple dice program
    By akira25 in forum Object Oriented Programming
    Replies: 3
    Last Post: April 9th, 2012, 04:46 AM
  3. Replies: 3
    Last Post: October 31st, 2011, 12:42 AM
  4. [SOLVED] Help figuring out why my method isn't executing as expected.
    By Herah in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 8th, 2011, 05:27 PM
  5. Simple java method problem
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 17th, 2011, 10:39 PM