• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

Sybex OCP Java Programmer 1 Study Guide 1Z0-815, Page 486 Review Question #6

 
Greenhorn
Posts: 22
Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please explain how a main method inside the java module can be run? I put the main method inside the module but it is giving compiler error.


The following question #6 has taken from Review Questions of Exercise Number 11 on page 486 of OCP Java Programmer 1 Study Guide Exam 1Z0-815 by Jeanne and Scott

6. What is true of a module containing a file named module-info.java with the following contents? (Choose all that apply.)

A. All packages inside the module are automatically exported.
B. No packages inside the module are automatically exported.
C. A main method inside the module can be run.
D. A main method inside the module cannot be run since the class is not exposed.
E. The module-info.java file contains a compiler error.
F. The module-info.java filename is incorrect.

The correct answers are B and C as per author.
module-info.png
[Thumbnail for module-info.png]
 
Ranch Hand
Posts: 34
5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amir Shah wrote:Can you please explain how a main method inside the java module can be run? I put the main method inside the module but it is giving compiler error.


It cannot be run in the module-info.java file*.
The main method can be run inside the module if you place the main method inside the class defined inside the module.
For example, we can define the main() method inside the Task.java which is in the zoo.animal.feeding module



Amir Shah wrote:(...)
C. A main method inside the module can be run.
D. A main method inside the module cannot be run since the class is not exposed.
(...)


I think these answers do not refer to the module-info.java file itself but the whole module.

--
* unless you use there a *class* instead of the *module* keyword and remove the directives (exports, requires etc.) making it a class
main_inside_the_module.png
[Thumbnail for main_inside_the_module.png]
 
author & internet detective
Posts: 40685
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cow to Tomasz  for explaining this really well!
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic