Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJP Question confusion example � need suggestion

 
Nitin Bhagwat
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • 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?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep to the well established Mock exams. This one is clearly rubbish.
 
Atul Chandran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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..
 
Kailas Lovlekar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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!
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic