Results 1 to 11 of 11
- 07-14-2010, 01:10 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
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); } }
-
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].
- 07-14-2010, 01:45 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
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
- 07-14-2010, 01:51 AM #4
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.
- 07-14-2010, 02:05 AM #5
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
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?
- 07-14-2010, 02:08 AM #6
Probably.I am just running it wrong
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.
- 07-14-2010, 05:59 AM #7
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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!
- 07-14-2010, 06:27 AM #8
make sure your java file name is same with main class method...
matur nuwun
- 07-15-2010, 04:35 AM #9
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
as far as I remember java defaults to protected scope not public
- 07-15-2010, 06:32 AM #10
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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!
- 07-16-2010, 12:34 AM #11
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
What am I doing wrong?
By yankeefan9874 in forum New To JavaReplies: 1Last Post: 04-16-2010, 08:54 AM -
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM -
Please help, what am I doing wrong?
By mmac1218 in forum New To JavaReplies: 2Last Post: 09-01-2009, 11:21 PM -
what wrong
By pro85 in forum New To JavaReplies: 3Last Post: 02-09-2009, 01:07 PM -
Can someone tell me what I did wrong??
By booter4429 in forum New To JavaReplies: 7Last Post: 08-13-2008, 08:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks