About Question enthuware.ocajp.i.v8.2.873 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
mj.anjuthan
Posts: 10
Joined: Thu Nov 10, 2016 3:07 am
Contact:

About Question enthuware.ocajp.i.v8.2.873 :

Post by mj.anjuthan »

Some candidates have reported getting a similar question with ambiguous options such as "An ArrayList implements Collection API". It is anybody's guess as to what is the correct answer.
What do you mean by this? Does not this option correct?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.873 :

Post by admin »

It means, we cannot suggest a correct answer in such case because it is not a technical issue but is about what oracle thinks.
Paul.
If you like our products and services, please help us by posting your review here.

JuergGogo
Posts: 28
Joined: Mon Sep 25, 2017 8:16 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.873 :

Post by JuergGogo »

Code: Select all

public class TestClass{
   public static void main(String args[]){
        
       String[] sa = new String[10];
       Object[] oa = sa;
       sa[0] = new Integer(10);  // compiler error: incompatible types: Integer cannot be converted to String
       oa[0] = new Integer(10);  // compiles fine, but ArrayStoreException
       
       ((String[])oa) [0] = new String("abc");   // ok
   }
}
This is a hole in the type safety provided by arrays.
I'm starting to understand type safety which enables the compiler to detect errors and therefore avoid runtime exceptions.

61d14837
Posts: 13
Joined: Tue Jul 21, 2020 1:39 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.873 :

Post by 61d14837 »

This will compile fine but will fail at runtime. This is a hole in the type safety provided by arrays.
If ArrayList doesn't have this hole, then why is option 4 incorrect?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.873 :

Post by admin »

There are other issues related to type safety in ArrayList. Neither is perfect.
But yes, which one is better in terms of type safety could be a bit subjective and depends on requirements. If you feel option 4 is correct, that's fine.
If you like our products and services, please help us by posting your review here.

61d14837
Posts: 13
Joined: Tue Jul 21, 2020 1:39 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.873 :

Post by 61d14837 »

Agreed, neither is perfect. Thanks for the feedback.

Post Reply

Who is online

Users browsing this forum: No registered users and 69 guests