Ensurepass.com : Ensure you pass the IT Exams
2018 Jan Oracle Official New Released 1z0-808
100% Free Download! 100% Pass Guaranteed!
http://www.EnsurePass.com/1z0-808.html
Java SE 8 Programmer I
Question No: 1
Given the code fragment:
public class Test {
public static void main(String[] args) { boolean isChecked = false;
int arry[] = {1,3,5,7,8,9};
int index = arry.length; while ( lt;code1gt; ) {
if (arry[index-1] % 2 ==0) { isChecked = true;
}
lt;code2gt;
}
System.out.print(arry(index] quot;, quot; isChecked));
}
}
Which set of changes enable the code to print 1, true?
-
Replacing lt;code1gt; with index gt; 0 and replacing lt;code2gt; with index-;
-
Replacing lt;code1gt; with index gt; 0 and replacing lt;code2gt; with -index;
-
Replacing lt;code1gt; with index gt; 5 and replacing lt;code2gt; with -index ;
-
Replacing lt;code1gt; with index and replacing lt;code2gt; with -index ;
Answer: A Explanation:
Note: Code in B (code2 is -index;). also works fine.
Question No: 2
Given:
What is the result?
-
Option A
-
Option B
-
Option C
-
Option D
Answer: D
Question No: 3
Given:
What is the output?
A. 1Z0
B. 1Z0-808
-
An exception will be thrown.
-
Compilation fails due to error at line 3.
-
Compilation tails due to error at line 4.
Answer: E Explanation:
Option E is the correct answer.
Code fails to compile because there is no method called concert in StringBuilder class. The concert method is in String class. Hence option E is correct Here we should have used append method of StringBuilder class, in that case option B would be correct. https://docs.oracle.com/javase/tutorial/java/data/buffers.html
Question No: 4
Given:
public class String1 {
public static void main(String[] args) { String s = quot;123quot;;
if (s.length() gt;2)
s.concat(quot;456quot;);
for(int x = 0; x lt;3; x ) s = quot;xquot;;
System.out.println(s);
}
}
What is the result?
A. 123
B. 123xxx
C. 123456
D. 123456xxx
E. Compilation fails
Answer: B Explanation: 123xxx
The if clause is not applied.
Note: Syntax of if-statement: if ( Statement ) {
}
Question No: 5
Given the code fragment:
What is the result?
-
Sum is 600
-
Compilation fails at line n1.
-
Compilation fails at line n2.
-
A ClassCastException is thrown at line n1.
-
A ClassCastException is thrown at line n2.
Answer: C
Question No: 6
Given:
public class ComputeSum { public int x;
public int y; public int sum;
public ComputeSum (int nx, int ny) { x = nx; y =ny;
updateSum();
}
public void setX(int nx) { x = nx; updateSum();} public void setY(int ny) { x = ny; updateSum();} void updateSum() { sum = x y;}
}
This class needs to protect an invariant on the sum field.
Which three members must have the private access modifier to ensure that this invariant is maintained?
-
The x field
-
The y field
-
The sum field
-
The ComputerSum ( ) constructor
-
The setX ( ) method
-
The setY ( ) method
Answer: C,E,F
Explanation: The sum field and the two methods (setX and SetY) that updates the sum field.
Question No: 7
Given the code fragment:
What is the result if the integer aVar is 9?
-
10 Hello World!
-
Hello Universe!
-
Hello World!
-
Compilation fails.
Answer: A
Question No: 8
Which statement will empty the contents of a StringBuilder variable named sb?
-
sb.deleteAll();
-
sb.delete(0, sb.size());
-
sb.delete(0, sb.length());
-
sb.removeAll();
Answer: C
Question No: 9
Given:
class Base {
// insert code here
}
public class Derived extends Base{ public static void main(String[] args) { Derived obj = new Derived(); obj.setNum(3);
System.out.println(quot;Square = quot; obj.getNum() * obj.getNum());
}
}
Which two options, when inserted independently inside class Base, ensure that the class is being properly encapsulated and allow the program to execute and print the square of the number?
-
private int num; public int getNum() { return num; }public void setNum(int num) { this.num = num;}
-
public int num; protected public int getNum() { return num; }protected public void setNum(int num) { this.num = num;}
-
private int num;public int getNum() {return num;} private void setNum(int num) { this.num = num;}
-
protected int num; public int getNum() { return num; } public void setNum(int num) { this.num = num;}
-
protected int num; private int getNum() { return num; } public void setNum(int num) { this.num = num;}
Answer: A,D Explanation: Incorrect:
Not B: illegal combination of modifiers: protected and public not C: setNum method cannot be private.
not E: getNum method cannot be private.
Question No: 10
Which two are valid array declaration?
-
Object array[];
-
Boolean array[3];
-
int[] array;
-
Float[2] array;
Answer: A,C
100% Ensurepass Free Download!
–Download Free Demo:1z0-808 Demo PDF
100% Ensurepass Free Guaranteed!
–1z0-808 Dumps
EnsurePass | ExamCollection | Testking | |
---|---|---|---|
Lowest Price Guarantee | Yes | No | No |
Up-to-Dated | Yes | No | No |
Real Questions | Yes | No | No |
Explanation | Yes | No | No |
PDF VCE | Yes | No | No |
Free VCE Simulator | Yes | No | No |
Instant Download | Yes | No | No |
100-105 Dumps VCE PDF
200-105 Dumps VCE PDF
300-101 Dumps VCE PDF
300-115 Dumps VCE PDF
300-135 Dumps VCE PDF
300-320 Dumps VCE PDF
400-101 Dumps VCE PDF
640-911 Dumps VCE PDF
640-916 Dumps VCE PDF
70-410 Dumps VCE PDF
70-411 Dumps VCE PDF
70-412 Dumps VCE PDF
70-413 Dumps VCE PDF
70-414 Dumps VCE PDF
70-417 Dumps VCE PDF
70-461 Dumps VCE PDF
70-462 Dumps VCE PDF
70-463 Dumps VCE PDF
70-464 Dumps VCE PDF
70-465 Dumps VCE PDF
70-480 Dumps VCE PDF
70-483 Dumps VCE PDF
70-486 Dumps VCE PDF
70-487 Dumps VCE PDF
220-901 Dumps VCE PDF
220-902 Dumps VCE PDF
N10-006 Dumps VCE PDF
SY0-401 Dumps VCE PDF