Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jaworski (http://www.jaworski.com/java/certification/) has a question like
In order of MyProgram to be compiled & run, which are true?
Athe MyProgram class must be defined in MyProgram.java
BMyProgram must be declared public
CMyProgram must have a correctly formed main() met.
DMyProgram must import java.lang
and the answre is only B.
is not A also correct?
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not necessarily, because the class could be defined in a package along with other classes, right??
Savithri
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in a package,only one class can be public.and that class name is used to name the file.so,...i think 'a' is also correct.what do u say?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think C should be the only condition.
-Maha
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not C because you don't have to have a main like with applets. It is not D because you don't have to import java.lang.
Now for A and B. I would think 'A' would be true because the question says in order to run and compile MyProgram. If you are running MyProgram then you would have to have it in a file MyProgram.java, correct? When I tried doing this, I got a NoClassDefFound runtime error. As for 'B', I don't think B is correct because a class can be a 'friendly' class and still compile and run. It can't be private or protected, but it can be 'friendly' or public. So I would have said only 'A' is correct.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic