permaculture playing cards*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "John Meyers Watch "John Meyers New topic
Author

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
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Hi.

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
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: John Meyers's SCJP mock errata
 
Similar Threads
Mock Question on Generics
Generics question?
Help with clarity on this Generics question
Genericss
need suggestions for SCJP 1.5 preparation