1Z0-808 - Java SE 8 Programmer
1Z0-808 - Java SE 8 Programmer
Java SE 8 Programmer |
Exam A
QUESTION 1
Given:
}
What is the result?
A. True false
B. True null
C. Compilation fails
D. A NullPointerException is thrown at runtime
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 2
Given the code fragment:
} else f{
System.out.println(aVar +
Hello Universe!");
}
A. Hello World!
B. Hello Universe!
C. Hello World
D. Compilation fails.
gorrect Answer: A
ection: (none)
Explanation
Explanation/Reference:
QUESTION 3
Given:
class Product {
double price;
}
}
What is the result?
A. 200.0: 100.0
B. 400.0 : 200.0
C. 400.0: 100.0
D. Compilation fails.
ortect newer: B
ection: (none)
Explanation
Explanation/Reference:
QUESTION 4
Given the code fragment:
1. class X {
oY; }
6. }
HB Be }
2: 2
Which two modifications should you make so that the code compiles successfully?
O A) Replace line 8 with public static void main(String[] args) throws Except
Option A
Option B
. Option C
Option D
Option E
moow>
Correct Answer: AC
Section: (none)
Explanation
Explanation/Reference:
QUESTION 5
Given the code fragment:
public static void main(String[] args) {
String date = LocalDate
. parse ("2014-05-04")
. format (DateTimeFormatter.ISO_ DATE TIME);
System.out.println (date);
}
5/4/14T00:00:00.000
An exception is thrown at runtime.
OO p>
Gorrect nswer: D
ection: none)
Explanation
Explanation/Reference:
Reference:
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
(see
predefined formatters)
QUESTION 6
Given the code fragment:
if (sb.equals(s)) {
System.out.println("Match 1");
} else if (sb.toString().equals(s.toString())) {
System.out.printlin("Match 2");
} else {
System.out.println("No Match");
>
Match 1
B. Match 2
C. No Match
Explanation
Explanation/Reference:
QUESTION 7
Given the following two classes:
/fline nil
How should you write methods in the ElectricAccount class at line n1 so that the
member variable bill is always
equal to the value of the member variable kwh multiplied by the member variable
rate?
method. An instance of the customer class should never be able to tamper with or
decrease the value of the
member variable bill.
Cc A) public void addkKWh(double kWh) {
this.kWh += kWh;
this.bill = this.kWh*this. rate;
}
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: AC
Section: (none)
Explanation
Explanation/Reference:
QUESTION 8
Given:
public static void main(String[] args)
ta = ta.concat (tb);
ta.replace('C’, ‘"D");
ta = ta.concat (tb);
System.out.println (ta);
}
ABCD
ACD
ABCC
ABD
ABDC
moom>
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 9
Given:
interface Readable {
public void readBook({);
public void setBookMark ();
}
f/f line n3
c A) Replace the code fragment at line ni with:
class Book implements Readable {
© B) At line n2 insert:
public abstract void setBookMark();
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 10
Given the code fragment:
Which option can replace xxx to enable the code to print 135?
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 11
Given:
class CD {
Erte £y
CDf{int r){
this.r=r;
}
}
Ents
DVD(int r, int c) {
f/f line nl
}
}
And given the code fragment:
Which code fragment should you use at line n1 to instantiate the dvd object
successfully?
C A) super.r = r;
this.c = c;
C B) super (r);
this (c);
© C) super(r);
this.c = ¢;
CD) thisic = r;
super (c);
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 12
Given the code fragment from three files:
SalesMan. java:
package sales;
public class SalesMan { }
Product. java:
package sales.products;
public class Product { }
Market. Java:
. package market;
Hop WN Ee
Which code fragment, when inserted at line 2, enables the code to compile?
~ A) import sales.*;
C B) import java.sales. products.*;
© C) import sales;
import sales.products;
© D) import sales.*;
import products.*;
Cc E) import sales.*;
import sales. products.*;
A. Option A
. Option B
C. Option C
D. Option D
E. Option E
Correct Answer: E
Section: (none)
Explanation
Explanation/Reference:
QUESTION 13
Which statement best describes encapsulation?
A. Encapsulation ensures that classes can be designed so that only certain fields
and methods of an object
are accessible from other objects.
Encapsulation ensures that classes can be designed so that their methods are
inheritable.
Encapsulation ensures that classes can be designed with some fields and methods
declared as abstract.
ow
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 14
Given the code fragment:
indextt;
Option A
Option B
. Option C
Option D
9Om>
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 15
Given the following class:
public class CheckingAccount {
public int amount;
public CheckingAccount (int amount) {
this.amount = amount;
}
public int getAmount () {
return amount;
}
public void changeAmount (int x) {
amount += x;
}
}
Which three lines, when inserted independently at line n1, cause the program to
print a o balance?
this.amount = 0;
amount = 0;
. acct (0);
. acct.amount = 0;
acct. getAmount () = 0;
acct.changeAmount(0);
acct.changeAmount(-acct.amount);
acct.changeAmount(-acct.getAmount());
rammoo mp
Explanation
Explanation/Reference:
QUESTION 16
Given the code fragment:
3. public static void main(String[] args) {
4 int x = 5;
5 while (isAvailable(x)) {
oO
}
10.
11. public static boolean isAvailable {int x) {
Les. return x-- > 0 ? true : false;
ESts }
B
C. Replace line 6 with --x; and, at line 7, insert system, out. print (x);
D. Replace line 12 With return (x > QO) ? false: true;
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 17
Given the code fragment:
}
What is the result?
A. Reading Card
Checking Card
B. Compilation fails only at line n1.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 18
Given the following main method:
int num = 5;
do f{
A. 543210
B. 54321
C. 421
D. 5
E. Nothing is printed
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 19
Given the code fragment:
6. switch (opt) {
7? case true:
8 System.out.print ("True");
oO
break;
10. default:
#2. System.out. print ("***");
eee }
LS: System.out.println("Done");
14. }
Which modification enables the code fragment to print TrueDone?
gorrect Answer: A
ection: (none)
Explanation
Explanation/Reference:
QUESTION 20
Given:
chs[a][b] = "" + a;
L++;
}
}
for (String[] ca : chs) {
for (String c : ca) {
System.out.print(c + " ");
}
System.out.println();
91 98
. Compilation rails.
900
E. An ArraylndexOutOfBoundsException is thrown at runtime.
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 21
int «x = 100%
int a = xtt;
int b = ++x;
int ¢c = xtt;
System.out.println (d) ;
100
101
102
103
Compilation fails
moO >
Correct Answer: E
Section: (none)
Explanation
Explanation/Reference:
QUESTION 22
Given the code fragment:
B. [Robb, Rick]
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 23
Given the code fragment:
:" + salary;
}
public static void main(String[] args) {
Employee e = new Employee ();
// line n2
System.out. print (6);
Which two modifications, when made independently, enable the code to print
joe:true: 100.0?
O A) Replace line n2 with:
e.name = "Joe";
e.contract = true;
e.salary = 100;
Option A
Option B
. Option C
Option D
Option E
moow>
Correct Answer: AC
Section: (none)
Explanation
Explanation/Reference:
QUESTION 24
Given:
class X {
static int i;
int Jj;
public static void main(String[] args) {
X xl = new X();
xX x2 = new Xj);
pad BEE Za
x1.4 4;
2... 4. 33
x2.) = 6;
System. out. println(
xl.a +" " +
Sy OS
x2.i+¢ " " 4+
OED Ys
A. 3456
B. 3436
C. 5456
D. 3646
ection: (none
Explanation
orrect Answer: C
§ J
Explanation/Reference:
QUESTION 25
Given:
class A f{
public A(){
System.out. print ("A ");
}
}
class B extends Af
public B{){ f/fline nl
System.out.print("B ");
}
}
class C extends Bf
A. CBA
B. C
Cc. ABC
Gorrect Answe :C
ection: (none
Explanation
Explanation/Reference:
QUESTION 26
Given the code fragment:
D. Compilation fails
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 27
Given the code fragment:
aosarnuwner NP
Which code fragment, when inserted at line 3, enables the code to print 10:20?
array = int[2];
C. int array = new int[2];
D. int array [2] ;
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 28
Given the code from the Greeting.Java file:
Co
‘ A) javac Greeting
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 29
Which three are advantages of the Java exception mechanism?
A.
mo ow
Improves the program structure because the error handling code is separated from
the normal program
function
Provides a set of standard exceptions that covers all the possible errors ;
Improves the program structure because the programmer can choose where to handle
exceptions
Improves the program structure because exceptions must be handled in the method in
which they occurred
Allows the creation of new exceptions that are tailored to the particular program
being created
Explanation
Explanation/Reference:
Reference: http://javajee.com/introduction-to-exceptions-in-java
QUESTION 30
Given the code fragment:
int ii = 0}
int jj = 7;
A. 24
B. 0246
Cc. 024
D. Compilation fails
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 31
Given:
class Alpha {
int ns;
static int s;
Alpha(int ns) {
if {$e < ns) {
s = ns;
thissns = ns;
}
}
vwoid doPrint() {
System.out.println("ns = "+ ns+" 5s =" 4+ s);
}
}
And,
cB) ns = 50 s = 125
ns = 125 s = 125
ns = 0s = 125
c C) ns = 50 s = SO
ns = 125 s = 125
ns = 100 s 100
cD) ns = 50s = 50
ns = 125 s = 125
ns Os = 125
Option A
Option B
. Option C
Option D
9Om>
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 32
Given the code fragment:
Which code fragment, when inserted at line 9, enables the code to print true?
90 wp
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 33
Given the code fragment:
Assume that the system date is June 20, 2014. What is the result?
c A) datel = 2014-06-20
date2 = 2014-06-20
date3 = 2014-06-20
c B) datel = 06/20/2014
date2 = 2014-06-20
date3 = Jun 20, 2014
© C) Compilation fails.
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 34
Given the code fragment:
double discount = 0;
int qty = Integer. parseInt (args[0]);
f/fline ni;
{ discount
OB) discount
discount
OC) discount
discount = 0.2;
} else f{
discount = 0;
}
if (qty >= 90) {
discount = 0.5;
} else {
discount = 0;
}
OE) discount
Option A
Option B
. Option C
Option D
Option E
moow>
Correct Answer: AC
Section: (none)
Explanation
Explanation/Reference:
QUESTION 35
a.
a.
0.5% 3
{ discount = 0.2; }
5 0;
0;
5 (qty > 80)? 0.2
(qty >= 90) ? 0.
O;
public class Test {
A. 10:10
B. 5:5
C. 5:10
D. Compilation fails
gorrect nswer: A
ection: (none)
Explanation
Explanation/Reference:
QUESTION 36
Which three statements describe the object-oriented features of the Java language?
"MOO w>
Explanation
Explanation/Reference:
+ check2. count);
QUESTION 37
Given:
javac Test.Java
Java Test Hello
A. Success
. Failure
B
C. Compilation fails.
D. An exception is thrown at runtime
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 38
You are developing a banking module. You have developed a class named ccMask that
has a maskcc method.
class CCMask {
public static String maskCC (String creditCard) {
String x = "XXXX-XXXK-XXXX-";
//line nil
}
You must ensure that the maskcc method returns a string that hides all digits of
the credit card number except
the four last digits (and the hyphens that separate each group of four digits).
Which two code fragments should you use at line n1, independently, to achieve this
requirement?
OF A) StringBuilder sb = new StringBuilder (creditCard) ;
sb.substring(15, 19);
return x + sb;
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: BC
Section: (none)
Explanation
Explanation/Reference:
QUESTION 39
Given the following code:
System.out.printlin(planets.length) ;
System.out.println(planets[1].length{));
}
7™M9O0OW >
ARORA
orrect newer: B
ection: (none)
Explanation
Explanation/Reference:
QUESTION 40
Given:
Base. java:
class Base {
public void test (){
System.out.println("Base ");
}
}
DerivedA. java:
DerivedB. java:
b4.test ();
A. Base
DerivedA
B. Base
DerivedB
C. DerivedB
DerivedB
D. DerivedB
DerivedA
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 41
Given:
package pl;
Test.java:
package p2;
import pl.Acc;
public class Test extends Acc {
public static void main(String[] args)
Acc obj] = new Test ();
}
}
A
B
C. Bothr and s are accessible by obj.
D. p,r, and s are accessible by obj.
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 42
Given:
nN
N
ae
U3
ae
ney
cB) 5 +
5 +2
i}
~]
cCQ7=7
te
cD) 5 + =
B+ 2 S79
nN
3
nw
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 43
Given the code fragment:
try {
while (true) {
myList.add("My String”);
}
}
catch (RuntimeException re) |
System. out.printin("Caught a RuntimeException"”) ;
}
catch (Exception ¢) {
System.out.printin("Caught an Exception");
}
System. out. printin("Ready to use");
What is the result?
moO D>
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 44
Given the code fragment:
}
}
continue;
A. ABC
B. ABCDE
C. ABDE
D. Compilation fails.
Gorrect Answe :C
ection: (none
Explanation
Explanation/Reference:
QUESTION 45
Given the code fragments:
Person. java:
Test.java:
Which code fragment, when inserted at line n1, enables the code to print Hank?
com>
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 46
Given the code fragment:
System.out.println ("Equal");
} else {
System.out.println("Not Equal");
}
Which code fragment, when inserted at line n1, enables the App class to print
Equal?
Cc B) if (strl.equalsIgnoreCase (str2) )
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 47
Given the code fragment:
A. true true
B. true false
C. false false
D. false true
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 48
Given the code fragment:
int. idx = 0;
A. Element 0
Element 1
ull lgment 4
C. Null
Null
orrect newer: D
ection: none)
Explanation
Explanation/Reference:
QUESTION 49
Given:
public class SumTest {
c A) int sum is 30
float. sum is 30.0
c B) int sum is 30
double sum is 30
© C) Integer sum is 30
double sum is 30.0
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: B
Section: (none)
Explanation
Explanation/Reference:
QUESTION 50
Given the definitions of the MyString class and the Test class:
MyString.java:
package pl;
class MyString {
String msg;
MyString (String msg)
this.msg = msg;
}
}
Test.java:
package pl;
public class Test {
System.out.println("Hello
Cc A) Hello Java SE 8
Hello Java SE 8
© C) Hello Java SE 8
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 51
Given:
class Vehicle {
int x;
Vehicle (){
this(10); // line nl
}
Vehiclefint x) {
this.x = x}
}
}
A. 10:20
. 0:20
B
C. Compilation fails at line n1
D. Compilation fails at line n2
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 52
Given:
MainTest.java:
public class MainTest {
and commands:
A. int main 1
B. Object main 1
C. String main 1
D
E
. Compilation fails
. An exception is thrown at runtime
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 53
Given the code fragment:
7 iVar = Var;
8. fVar = iVar;
9, dVar = fVar;
10. fVar = dVar;
3's, }
Which three lines fail to compile?
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
™mOO Ww >
Section: (none)
Explanation
Explanation/Reference:
QUESTION 54
Given the code fragment:
}
What is the result?
A. Jesse 25
Walter 52
B. Compilation fails only at line n4
/fline nl
//line n2
C. Compilation fails only at line n2
D. Compilation fails at both line n1 and line n2
Gorrect Answer: B
ection: (none)
Explanation
Explanation/Reference:
QUESTION 55
Given the code fragment:
Which option represents the state of the num array after successful completion of
the outer loop?
C A) num[0] [0]=10
num [0] [1]=10
num [0] [2]=10
© B) num[0O] [0]=10
num[1] [0]=10
num[2] [0]=10
© D) num[0] [(0]=10
num[O] [1]=10
num[O)] [2]=10
num[0] [3]=10
num[1] [0]=0
num[1] [1]=0
num[1] [2] =0
num[1] [3]=0
A. Option A
B. Option B
C. Option C
D. Option D
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 56
Given the following array:
Which two code fragments, independently, print each element in this array?
Option A
Option B
. Option C
. Option D
. Option E
. Option F
™m™9U0ONP
Correct Answer: BE
Section: (none)
Explanation
Explanation/Reference:
QUESTION 57
Given the following code for a Planet object:
}
And the following main method:
}e
System.out.println(planets) ;
System.out.println(planets[2]};
System. out. println(planets[2].moons);
{
c A) planets
Earth
1
Option A
Option B
. Option C
Option D
Option E
moow>
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 58
Given the code fragment:
int] array = {l, 2, 3, 4, 5};
2. Process all the elements of the array in the reverse order of entry.
3. Process alternating elements of the array in the order of entry.
moo wp
Correct Answer: DE
Section: (none)
Explanation
Explanation/Reference:
QUESTION 59
Given the content of three files:
A.java:
public class A {
public void a() {}
int a;
B.java:
public class B {
private int doStuff() {
private int x = 100;
return x+t+;
}
C.java:
import jJava.io.*;
package pl;
class A {
public void main(String fileName) throws IOException { }
T7mO0 w>
Correct Answer: E
Section: (none)
Explanation
Explanation/Reference:
QUESTION 60
Given the following class declarations:
Option A
Option B
. Option C
Option D
Option E
moow>
Correct Answer: E
Section: (none)
Explanation
Explanation/Reference:
QUESTION 61
Given:
A. 400 200
B. 200 200
C. 400 400
D. Compilation fails.
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 62
Given:
int num;
9085}
RON =
gorrect Answer: A
ection: (none)
Explanation
Explanation/Reference:
QUESTION 63
Which statement is true about Java byte code?
A
B
C. It can run on any platform that has the Java Runtime Environment.
D. Itcan run on any platform that has a Java compiler.
E. It can run on any platform only if that platform has both the Java Runtime
Environment and a Java compiler.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
Reference: http://www.math.uni-hamburg.de/doc/java/tutorial/getStarted/intro/
definition.htm|
Explanation:
Java bytecodes help make "write once, run anywhere" possible. You can compile your
program into bytecodes
on any platform that has a Java compiler. The bytecodes can then be run on any
implementation of the Java
VM. That means that as long as a computer has a Java VM, the same program written
in the Java
programming language can run on Windows 2000, a Solaris workstation, or on an iMac.
QUESTION 64
Given the code fragment:
/fline nl
switch (x) {
case 1:
System.out.println("One");
break;
case 2:
System.out.println ("Two");
break;
Which three code fragments can be independently inserted at line nl to enable the
code to print one?
B. Sorex = 4:
C. String x = "1";
D. Long x = 1;
E. Double x = 1;
Explanation
Explanation/Reference:
QUESTION 65
Given:
public class Triangle {
static double area;
int: b = 2) hn = 3;
public static void main(String[] args) {
A. Area is 6.0
B. Area is 3.0
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference: