Results 1 to 11 of 11
  1. #1
    Basilisk3 is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default Can someone look at this a tell me what I am doing wrong?

    I am new and I cannot get this to run. Am I leaving something out? Any advise? Thanks. I am sure it is just something stupid.

    Java Code:
    class OverloadDemo
    {
    	void test()
    	{
    	
    	System.out.println("No Parameters");
    	}
    	
    	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 Overload
    {
    	public static void main(String args [])
    	{
    		OverloadDemo ob = new OverloadDemo();
    		double result;
    	// call all versions of test()
    	ob.test ( );
    	ob.test (10);
    	ob.test (10,20);
    	result = ob.test (123.2);
    	System.out.println("result of ob.test (123.2) : " + result);
    	}
    	
    }

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

    Default

    You need to tell us more, a lot more. For instance, what is your code doing that it shouldn't be doing, what is it not doing that it should be doing, what error messages, if any, do you see. Also, please note that for code tags to work, the bottom tag should be [/code].

  3. #3
    Basilisk3 is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default

    Sorry about that. I can get it to compile but when I run it I get the following error

    java.lang.NoSuchMethodError: main
    Exception in thread "main"

    I was given this code to copy and compile and run, to see what it does and I cannot get it to run to see what it does. I have been pulling out me hair trying to figure out what I am missing. Thanks

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    What command line do you enter to run it?
    The main() method is in the Overload class.

    You should enter: 'java Overload' to execute the class with the main() method.

  5. #5
    Basilisk3 is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default

    I am not sure what you mean. I just enter it in JGrasp, compile it and select run. Sorry I am really new to all this. Are you saying it should work and I am just running it wrong?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    I am just running it wrong
    Probably.
    To execute the program your IDE must execute the command line: java Overload
    I have no idea how to configure your IDE to do that.

  7. #7
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Is the code all in the same file? not quite sure what would happen if you had the main method in a non-public class (Overload) in a differently named file (OverloadDemo.java/OverloadDemo.class) Could do some very odd things...
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  8. #8
    udinulis's Avatar
    udinulis is offline Member
    Join Date
    Jul 2010
    Location
    earth
    Posts
    8
    Rep Power
    0

    Default

    make sure your java file name is same with main class method...


    matur nuwun

  9. #9
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    as far as I remember java defaults to protected scope not public

  10. #10
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Quote Originally Posted by al_Marshy_1981 View Post
    as far as I remember java defaults to protected scope not public
    Not quite. 'package private' or default scope, is the default scope. You can't actually declare something as 'package private' - you only get that scope when you don't specify a scope in a class (undefined scope in interfaces and such being public static final or public abstract by default).
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  11. #11
    Basilisk3 is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default

    I figured it out. Thanks. I had both classes saved in the same file.

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. What am I doing wrong?
    By yankeefan9874 in forum New To Java
    Replies: 1
    Last Post: 04-16-2010, 08:54 AM
  3. Please help, what am I doing wrong?
    By mmac1218 in forum New To Java
    Replies: 2
    Last Post: 09-01-2009, 11:21 PM
  4. what wrong
    By pro85 in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 01:07 PM
  5. Can someone tell me what I did wrong??
    By booter4429 in forum New To Java
    Replies: 7
    Last Post: 08-13-2008, 08:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •