Results 1 to 11 of 11
- 06-28-2012, 08:06 AM #1
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
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);
}
}
- 06-28-2012, 08:31 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: main method not found error in class . wat s the error?
Can you tell how did you run your program?
Website: Learn Java by Examples
- 06-28-2012, 08:37 AM #3
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
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
- 06-28-2012, 09:28 AM #4
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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 MethodOverloadingLast edited by wsaryada; 06-28-2012 at 10:11 AM.
Website: Learn Java by Examples
- 06-28-2012, 09:31 AM #5
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Re: main method not found error in class . wat s the error?
shall u send that command please
- 06-28-2012, 09:31 AM #6
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Re: main method not found error in class . wat s the error?
fulfill the program and send it once again
- 06-28-2012, 09:59 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,451
- Rep Power
- 16
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.
- 06-28-2012, 10:42 AM #8
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
: 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
- 06-28-2012, 11:16 AM #9
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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.
Website: Learn Java by Examples
- 06-28-2012, 11:20 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,451
- Rep Power
- 16
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.
- 06-29-2012, 11:26 AM #11
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
Re: 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.main method not found error in class . wat s the error?
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
-
Main Method not found in class
By HinaKhan in forum New To JavaReplies: 6Last Post: 06-22-2012, 02:34 PM -
<No main classes found> Error
By hersman in forum NetBeansReplies: 2Last Post: 04-23-2011, 01:08 AM -
main method not found in class
By eLancaster in forum New To JavaReplies: 5Last Post: 02-09-2011, 08:48 AM -
No Class Def Found Error:
By fithous in forum Java AppletsReplies: 0Last Post: 04-02-2009, 05:30 PM -
No main class found error
By jhering1986 in forum New To JavaReplies: 17Last Post: 03-28-2009, 02:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks