Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/how-to-declare-instantiate-java-generic-collection
Question 75 / 297:  What is the result of compiling and running the following program?
import java.util.ArrayList;

import java.util.List;

public class Tester {

public static void main(String[] args) {

List<String> list1 = new ArrayList<String>();//line 1

List<Object> list2 = list1;//line 2

list2.add(new Integer(12));//line 3

System.out.println(list2.size());//line 4

}

}

A  Compilation error at line 1, must initialize the size
B  Compilation error at line 2,Type mismatch, cannot convert from List<String> to List<Object>
C  Compilation error at line 3, can add objects of type String only
D  1
<< First < Previous Next > Last >>
Explanation:

Type mismatch, can't convert from List<String> to List<Object>

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Brenna Fike
Start Quiz
Yacoub Jayoghli
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>