Page 1 of 1

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

Posted: Mon Nov 21, 2016 1:41 am
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?

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

Posted: Mon Nov 21, 2016 8:25 am
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.

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

Posted: Thu Oct 05, 2017 1:11 pm
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.

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

Posted: Sat Apr 17, 2021 1:29 pm
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?

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

Posted: Sun Apr 18, 2021 12:45 am
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.

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

Posted: Sun Apr 18, 2021 2:20 am
by 61d14837
Agreed, neither is perfect. Thanks for the feedback.

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

Posted: Sat Sep 27, 2025 12:52 am
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.

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

Posted: Sat Sep 27, 2025 2:04 am
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.