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: 10436
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.

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: 10436
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.

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.

Pratham2002
Posts: 1
Joined: Sat Sep 27, 2025 12:34 am
Contact:

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

Post by Pratham2002 »

Regarding first option, it says that we do not have to worry about the size of ArrayList while appending elements. But we cannot do so indefinitely since that would cause OutOfMemoryError. Shouldn't option 4 be right then? Since ArrayList are more type safe than Normal Arrays.

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

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

Post by admin »

No, in the given context the comparison is between array and ArrayList and in array you have to worry about the array size while adding or accessing elements irrespective of the total memory available.
OutOfMemoryError is an overarching concern that applies to everything. It has no relevance here.

Post Reply

Who is online

Users browsing this forum: No registered users and 106 guests