Help coderanch get a
new server
by contributing to the fundraiser
  • 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

SCJP Question confusion example � need suggestion

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is sample mock exam question:

When Integer object created at line 11 eligible for garbage collection?

10.public Object method1() {
11.Object ob = new Integer(30);
12.Object [] oo = new Object[1];
13.oo[0] = ob;
14.oo = null;
15.ob[0] = null;
16.print 'return 23';
17.}

A. Just after line 13
B. Just after line 14
C. Just after line 15
D. Just after line 16 (as method returns)

Ans given is C.
Actually, this program will not compile because, 1.No main method
2. line no. 16 will produce error.

My question is:
1. In real exam, if main method is not given, should we assume that?
2. If statement like 16 is wrong and program will produce error. So, actually we can not select any option.
3. In real exam, do we need to check errors like { } has correct start and end
4. Do we need to check if ; is added or missed for some statement

It would be nice if some one can tell, what should we do in above two cases in actual Exam?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep to the well established Mock exams. This one is clearly rubbish.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is just a snippet. And the absence of main method will never result in a compile time error it will only result in a runtime error. Line 15 will result in a compile time error because ob is not an array(It should have been ob=null) and I have no idea about line 16..
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. In real exam, if main method is not given, should we assume that?

Probably yes! Sun exam guidelines say you can assume that supporting code exists id it is a partial code. Because this is not a complete class you may assume that main method exists probably with other methods

2. If statement like 16 is wrong and program will produce error. So, actually we can not select any option.

No chance of this happening in real exam!

3. In real exam, do we need to check errors like { } has correct start and end
4. Do we need to check if ; is added or missed for some statement

Real exam does try to trick you on some questions and only way to prepare for that is through good mocks! Not mocks containing questions like this!
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Someone correct me if I'm wrong, but I believe that you only have to look out for a compiler error if that is one of the choices.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic