-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathch06a.html
69 lines (43 loc) · 2.64 KB
/
ch06a.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Study guide for the Oracle Certified Professional, Java SE 8 Programmer Exam ">
<title>Java 8 Programmer II Study Guide: Exam 1Z0-809</title>
<link href="css/code.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="js/common-sections.js"></script>
</head>
<body>
<div class="header">
<div class="title-container">
<div class="chapter-title">
<h1><i class="chapter">Chapter SIX</i><br />
Generics</h1>
<p><br /></p>
<h3 style="text-align: center;"><i>Exam Objectives</i></h3>
<p style="text-align: center;"><i>Create and use a generic class.</i></p>
</div>
</div>
</div>
<div class="container">
<div class="column">
<h2>Answers</h2>
<p><b>1. The correct answer is A.</b><br /> You can modify a list typed as <code>List<?></code>, but when you call <code>m2()</code>, inside that method, the list has a different type, <code>List<T></code>, which allows you to change the value of the second element.</p>
<p><br /></p>
<p><b>2. The correct answer is A.</b><br />
<code><T extends Number></code> means that you can assign a <code>Number</code> or one of its subclasses to the generic type. This applies to both, the type argument of the class <code>Question_6_2</code> and to the variable <code>t</code>.</p>
<p><br /></p>
<p><b>3. The correct answer is C.</b><br /> Option C doesn't compile because you can only assign a list of type <code>Object</code> to <code>l3</code>, the lower-bounded wildcard doesn't allow you to assign a subclass (like <code>String</code>).</p>
<p><br /></p>
<p><b>4. The correct answer is C.</b><br />
<code><? super Number></code> allows you to assign a <code>List</code> of type <code>Number</code> or its superclass, which is done in line <code>// 1</code>.</p>
<p>The list can contain instances of Number or one of its subclasses. Since line <code>// 3</code> tries to add an instance of the superclass of <code>Number (Object)</code>, this line generates a compile-time error.</p>
<p><br /></p>
</div>
</div>
<footer></footer>
</body>
</html>