• 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
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dan's exam: main method

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem with this question:

What is the result of attempting to compile and run the above programs?
a. Compile-time error at line 1.
b. Compile-time error at line 2.
c. Compile-time error at line 3.
d. An attempt to run GRC4 from the command line fails.
e. An attempt to run GRC5 from the command line fails.
f. An attempt to run GRC6 from the command line fails.
g. None of the above
The code WILL compile without problem but can't be executed unless the file name is GRC4, GRC5 or GRC6 - none of the classes is declared public so the main method can't be found. Even so, only one of the classes can be executed never all three (provided they're in the same file).
In my opinion, rephrasing needs to be done otherwise the correct answers should be D,E,F.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class is not visible to other classes in different packages, not to JVM, so why wouldn't it see it when you run it through command-line?
The answer is
g. None of the above
because it compiles and any of the 3 following command line invocations run fine:
java GRC4
java GRC5
java GRC6
P.S. Oh yeah, when you compile a java source file with n N classes in it, you will get N .class files and you can invoke them through command-line. In this example you'll get GRC4.class GRC5.class and GRC6.class (no matter what the .java filename is)
[ March 15, 2004: Message edited by: Yuriy Grechukhin ]
 
Bojan Knezovic
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yuriy Grechukhin:

P.S. Oh yeah, when you compile a java source file with n N classes in it, you will get N .class files and you can invoke them through command-line. In this example you'll get GRC4.class GRC5.class and GRC6.class (no matter what the .java filename is)



Hmmm... must admit I didn't know that. Thanks!
 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bojan,
every class creates a .class file, even inner classes.
Davy
 
reply
    Bookmark Topic Watch Topic
  • New Topic