What do you mean by this? Does not this option correct?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.
About Question enthuware.ocajp.i.v8.2.873 :
Moderator: admin
-
- Posts: 10
- Joined: Thu Nov 10, 2016 3:07 am
- Contact:
About Question enthuware.ocajp.i.v8.2.873 :
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.873 :
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.
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 28
- Joined: Mon Sep 25, 2017 8:16 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.873 :
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
}
}
I'm starting to understand type safety which enables the compiler to detect errors and therefore avoid runtime exceptions.This is a hole in the type safety provided by arrays.
-
- Posts: 13
- Joined: Tue Jul 21, 2020 1:39 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.873 :
If ArrayList doesn't have this hole, then why is option 4 incorrect?This will compile fine but will fail at runtime. This is a hole in the type safety provided by arrays.
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.873 :
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.
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.
-
- Posts: 13
- Joined: Tue Jul 21, 2020 1:39 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.873 :
Agreed, neither is perfect. Thanks for the feedback.
Who is online
Users browsing this forum: No registered users and 23 guests