Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Arrow main method not found error in class . wat s the error?

    class Overload2{

    void test(int a) {
    System.out.println("a: " + a);

    }

    void test(int a, int b) {
    System.out.println("a and b: " + a + "," + b);
    }

    double test(double a) {
    System.out.println("double a: " + a);
    return a*a;
    }
    }

    class MethodOverloading {
    public static void main(String[] args) {
    Overload2 overload = new Overload2();
    double result;
    overload.test(10);
    overload.test(10, 20);
    result = overload.test(5.5);
    System.out.println("Result : " + result);
    }
    }

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: main method not found error in class . wat s the error?

    Can you tell how did you run your program?

  3. #3
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Arrow Re: main method not found error in class . wat s the error?

    am writing program at edit plus
    and run by dos prompt
    can u pls give answer

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: main method not found error in class . wat s the error?

    When you get an error telling that main() method is not found in class that means you are trying to run a class that doesn't have a main() method. That's why I was asking how you run your program. I've executed your program using the following command and it executed.

    java MethodOverloading
    Last edited by wsaryada; 06-28-2012 at 10:11 AM.

  5. #5
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Re: main method not found error in class . wat s the error?

    shall u send that command please

  6. #6
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Arrow Re: main method not found error in class . wat s the error?

    fulfill the program and send it once again

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: main method not found error in class . wat s the error?

    How are you executing the code?
    What command are you using?
    What is the full error that you get (copy and paste it here)?

    And please use [code] tags [/code] when posting code.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Arrow : main method not found error in class overload2. please define main method as : pu

    : main method not found error in class overload2. please define main method as : public static void main (String args[])----------- this s the error




    class Overload2{

    void test(int a) {
    System.out.println("a: " + a);

    }

    void test(int a, int b) {
    System.out.println("a and b: " + a + "," + b);
    }

    double test(double a) {
    System.out.println("double a: " + a);
    return a*a;
    }
    }

    class MethodOverloading {
    public static void main(String[] args) {
    Overload2 overload = new Overload2();
    double result;
    overload.test(10);
    overload.test(10, 20);
    result = overload.test(5.5);
    System.out.println("Result : " + result);
    }
    }





    this s program

  9. #9
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: main method not found error in class . wat s the error?

    If you run the Overload2 class you'll get the error you've described. Because it doesn't have the main() method. You can only run a class that have an entry point, which is the main() method. In your example that would be the MethodOverloading class.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: main method not found error in class . wat s the error?

    And you didn't use [code] tags [/code] again...
    Oh, and that error doesn't match your code.
    'overload2' is not the same as 'Overload2'.
    I'm assuming you simply mistyped it, but Java is case-sensitive and that typo could imply another problem you have.
    Please ensure the information you provide is correct otherwise we will have trouble analysing your problem.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default Re: main method not found error in class . wat s the error?

    main method not found error in class . wat s the error?
    Your error is that if you have main method in class MethodOverloading that class should be public. For example it could look something like this.

    File: MethodOverloading.java

    Java Code:
    class Overload2 {
          // your code here
    }
    
    
    public class MethodOverloading {
          // your code here
    
          public static void main(String[] args) {
           // your code here
          }
    }
    
    }
    Last edited by cselic; 06-29-2012 at 11:29 AM.

Similar Threads

  1. Main Method not found in class
    By HinaKhan in forum New To Java
    Replies: 6
    Last Post: 06-22-2012, 02:34 PM
  2. <No main classes found> Error
    By hersman in forum NetBeans
    Replies: 2
    Last Post: 04-23-2011, 01:08 AM
  3. main method not found in class
    By eLancaster in forum New To Java
    Replies: 5
    Last Post: 02-09-2011, 08:48 AM
  4. No Class Def Found Error:
    By fithous in forum Java Applets
    Replies: 0
    Last Post: 04-02-2009, 05:30 PM
  5. No main class found error
    By jhering1986 in forum New To Java
    Replies: 17
    Last Post: 03-28-2009, 02:34 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
  •