The two programs are different; the error message shows that. The Exception occurs in line 16, which consists only of a } in the code you posted, and the class name has MalJavaChapter3 in; that means there is a package name which you have missed out when you quoted the code. You must always post the
real code with all the details, otherwise you will get the wrong answers.
The two classes you posted can be executed without any Exceptions. But it is possible that what you executed on Eclipse was slightly different. You have not shown any evidence that there is anything wrong with your Eclipse installation.