• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dan's exam ...

 
Salim Mohamed
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class ManyClasses {
public static void main(String[] r[]){
System.out.println("Hi");
}
}
class basic1 {
public static void main(String[] r[]){}
}
class basic2 {
public static void main(String[] r[]){}
}
class basic3 {
public static void main(String[] r[]){}
}
This doesnt cause compilation error. But I dont understand why this is causing runtime error :
Exception in thread "main" java.lang.NoSuchMethodError: main
even if this is stored in a file called ManyClasses.java.
Thanks in advance.
 
chintan desai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Salim,
This is because the main method in Class named ManyClasses is not the "public static void main(String args[])" , from where any program starts execution. The main method in this program is overloaded version of the "public static void main(String args[])" method, which has argument parameters as "String[] r[]" which is two dimensional array and that's not the correct syntax for main method. that's why it is compiling but giving error at runtime that there is no such main method with "String r[]" which has one dimentional String array.
Chintan.
 
Salim Mohamed
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for posting wrong piece of code. Thanks.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Salim Mohamed:
Sorry for posting wrong piece of code. Thanks.

I was wondering why that code didn't look familiar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic