File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes John Meyers's SCJP mock errata Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "John Meyers Watch "John Meyers New topic

John Meyers's SCJP mock errata

Kalpesh Jain
Ranch Hand

Joined: May 29, 2006
Posts: 30
Source for the below mentioned code:
John Meyers's SCJP mock exam@Java.Inquisition

And the options are:
a) Will not compile at line 1 and 2
b) will not compile at line 2
c) Has runtime errors.
D) Will compile
E) Will not compile at line 1

The correct answer is given as (b) but explanation provided was "List is required"
My question is, is this explanation justified?
I understand that if we return ArrayList where List is required compiler won't mind as covariant returns are allowed.
Moreover, if I change line 2 to return new ArrayList<T>();, code compiles just fine. So what must be the correct way to say why line 2 does not compile?

Its a j a v a
Deepak Bala

Joined: Feb 24, 2006
Posts: 6657


First up thanks for trying the exam. Although the answer says a List of type T is required it is just one of the right answers. Since a List is an interface you would certainly have to use a linked list or an array list or something else that implements List when you pass the List reference as a return parameter ( the object the List reference points to I mean). The exception being of course when you pass a List reference pointing to null.

You are right about the co variant return part. You could as well return an ArrayList if you wish, as of java 5.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Kalpesh Jain
Ranch Hand

Joined: May 29, 2006
Posts: 30
John, Thanks for clarification.!!

And 1 more question, is toughness level of real SCJP 5.0 equivalent to this mock exam or SCJP is more tough?? plz give me a relative idea (so that I can prepare myself for worse or good )

Finally, I must compliment you that your mock questions are very good and I liked the inquisition application too. Thumbs UP!
Deepak Bala

Joined: Feb 24, 2006
Posts: 6657

Thank you.

The Inquisition application was not written by me. It was written by Matt. You can explore the site where Inquisition is located to get more details about the project. Only the mock exam that Inquisition hosts was written by me.

The real SCJP exam is pretty straight forward. I tried to set a difficulty level that is a notch or two greater than the real exam.

Thanks for trying my mock.
I agree. Here's the link:
subject: John Meyers's SCJP mock errata
Similar Threads
Generics question?
Mock Question on Generics
Help with clarity on this Generics question
need suggestions for SCJP 1.5 preparation