• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Override the main method

 
nemo zou
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got confused about the this question in Enthuware test 6. I thought the answer is "print nothing" because I remember it is fine to override the main methods. Why an error would be thrown here?
overridemain.png
[Thumbnail for overridemain.png]
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nemo zou wrote:I thought the answer is "print nothing" because I remember it is fine to override the main methods. Why an error would be thrown here?

First of all, that's not an override! Only inherited instance methods can be overridden.

Secondly, you'll get an error because the JVM is looking for a method public static void main (String[]) - exactly. So because the return type is long, the JVM can't find the main method to run your application and you'll get something like:
Error: Main method must return a value of type void in class TestClass, please define the main method as:
public static void main(String[] args)


Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic