Forums Register Login

Override the main method

+Pie Number of slices to send: Send
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
[overridemain.png]
+Pie Number of slices to send: Send
 

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
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 434 times.
Similar Threads
Scored 93% on OCA JP7 today
Where to find ans for mock test by Valentinn Cretazz
Rules Roundup Game: RuntimeExceptions and Math methods
K&B - Practice Exams book - Full Exam II - Question 48
over loaded methods??
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:02:06.