Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Boone's qns

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I just took the Boone mock exam. I am just a little doubful about the following qns. Can anybody help me?
1. What will happen when you attempt to compile and run the following program by passing the Test class to the Java interpreter?
class Test {
public static void main() {
System.out.println("hello");
}
}
Select the one right answer.
1. The program does not compile because main() is not defined correctly.
2. The program compiles but when you try to run the interpreter complains that it cannot find the main() method it needs to run.
3. The program compiles but you cannot run it because the class is not declared as public.
4. The program compiles and runs without an error but does not display anything in the standard output.
5. The program compiles and displays "hello" in the standard output when you run it.
The answer given is 2, but I think the answer should be 3 (and also 2, if multiple answers are allowed).

Question 65: Which statements about garbage collection are true?
Select all valid answers.
a. You can directly free the memory allocated by an object.
b. You can directly run the garbage collector whenever you want to.
c. The garbage collector informs your object when it is about to be garbage collected.
d. The garbage collector reclaims an object´┐Żs memory as soon as it becomes a candidate for garbage collection.
e. The garbage collector runs in low-memory situations.
My answer is c, e, but the answer given is b,c,e. I don't think b is correct 'coz you can't run the garbage collector, you can only request it to be run. Any suggestions?
Thanks,
Aman

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About the first question, What Boones says is right.
The following code will compile and run if you call it by
saying "java Test"
class Test {
public static void main(String args[]) {
System.out.println("hello");
}
}
The following code will compile and wont run
class Test {
public static void main() {
System.out.println("hello");
}
}

Note: The top level class could either be public or friendly.

------------------------------------------------------
About the following question,
"You can directly run the garbage collector whenever you want to."
-- I feel he tries to differentiate between "whether you could
run the garbage collector" and "whether it really collects any garbage or not". You might be able to run it when you want to but it collects garbage only when it wants to.
- This is my interpretation. Any takers ?
[This message has been edited by vasansrini (edited July 30, 2000).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic