forked from eh3rrera/ocpj8-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch08a.html
80 lines (48 loc) · 3.5 KB
/
ch08a.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
70
71
72
73
74
75
76
77
78
79
80
<!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 EIGHT</i><br />
Functional Interfaces</h1>
<p><br /></p>
<h3 style="text-align: center;"><i>Exam Objectives</i></h3>
<p style="text-align: center;"><i>Create and use Lambda expressions.</i></p>
</div>
</div>
</div>
<div class="container">
<div class="column">
<h2>Answers</h2>
<p><b>1. The correct answer is A.</b><br /> A functional interface must declare one abstract method. Since interface <code>B</code> only declares a static method and inherits a default one, it won't compile, not even by adding another default method or by having the <code>@FunctionalInterface</code> annotation.</p>
<p><br /></p>
<p><b>2. The correct answers are B and C.</b><br /> The code doesn't compile successfully. This is not a functional interface because it has two abstract methods (it doesn't matter they have the same name).</p>
<p>The <code>@FunctionalInterface</code> annotation throws an error if the interface it marks is not a functional one. If we remove it, the code compiles although, the interface is still not functional.</p>
<p>If we remove one method, no matter which, the interface becomes functional, making the code compile.</p>
<p>The <code>@FunctionalInterface</code> annotation doesn't make an interface functional; its job is just to make the compiler check if the interface is a functional one.</p>
<p><br /></p>
<p><b>3. The correct answers are A and C.</b><br /> There's nothing wrong with the code; it compiles successfully.</p>
<p>Functional interfaces can have any number of default methods, as long as they have only one abstract method. In this case, the code represents a functional interface. If we remove the sum method, we would be violating this rule and the interface wouldn't be functional anymore.</p>
<p><br /></p>
<p><b>4. The correct answers are A and D.</b><br />
<code>java.util.concurrent.Callable</code> is marked with the <code>@FunctionalInterface</code> annotation.</p>
<p>Although <code>java.lang.Comparable</code> is not marked with the <code>@FunctionalInterface</code> annotation, it can be considered one. Remember, this annotation doesn't make an interface functional.</p>
<p><br /></p>
<p><b>5. The correct answer is B.</b><br /> There's nothing wrong with this code; it compiles successfully. However, this is not a functional interface since it doesn't have an abstract method. Therefore, all other options are <code>false</code>.</p>
<p><br /></p>
</div>
</div>
<footer></footer>
</body>
</html>