Ensurepass.com : Ensure you pass the IT Exams
2018 Jan Oracle Official New Released 1z0-803
100% Free Download! 100% Pass Guaranteed!
http://www.EnsurePass.com/1z0-803.html
Java SE 7 Programmer I
Question No: 61
Given the code fragment int var1 = -5;
int var2 = var1-; int var3 = 0;
if (var2 lt; 0) { var3 = var2 ;
} else {
var3 = -var2;
}
System.out.println(var3);
What is the result?
-
– 6
-
– 4
-
– 5
-
5
-
4
-
Compilation fails
Answer: C
Question No: 62
Given:
public class MyClass {
public static void main(String[] args) { String s = quot; Java Duke quot;;
int len = s.trim().length(); System.out.print(len);
}
}
What is the result?
-
8
-
9
-
11
-
10
-
Compilation fails
Answer: B
Explanation: Java -String trim() Method
This method returns a copy of the string, with leading and trailing whitespace omitted.
Question No: 63
Given:
Which two are possible outputs?
-
Option A
-
Option B
-
Option C
-
Option D
Answer: A,D Explanation:
The first println statement, System.out.println(quot;Before if clausequot;);, will always run.
If Math.Random() gt; 0.5 then there is an exception. The exception message is displayed and the program terminates.
If Math.Random() gt; 0.5 is false, then the second println statement runs as well.
Question No: 64
Given the classes:
-
AssertionError
-
ArithmeticException
-
ArrayIndexOutofBoundsException
-
FileNotFoundException
-
IllegalArgumentException
-
IOError
-
IOException
-
NumberFormatException
-
SQLException
Which option lists only those classes that belong to the unchecked exception category?
-
AssertionError, ArrayIndexOutOfBoundsException, ArithmeticException
-
AssertionError, IOError, IOException
-
ArithmeticException, FileNotFoundException, NumberFormatException
-
FileNotFoundException, IOException, SQLException
-
ArrayIndexOutOfBoundException, IllegalArgumentException, FileNotFoundException
Answer: A
Explanation: Not B: IOError and IOException are both checked errors. Not C, not D, not E: FileNotFoundException is a checked error.
Note:
Checked exceptions:
-
represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files)
-
are subclasses of Exception
-
a method is obliged to establish a policy for all checked exceptions thrown by its implementation (either pass the checked exception further up the stack, or handle it somehow)
Note:
Unchecked exceptions:
-
represent defects in the program (bugs) – often invalid arguments passed to a non-private method. To quote from The Java Programming Language, by Gosling, Arnold, and Holmes: quot;Unchecked runtime exceptions represent conditions that, generally speaking,reflect errors in your program#39;s logic and cannot be reasonably recovered from at run time.quot;
-
are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, or IllegalStateException
-
method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so)
Question No: 65
Given:
What is the result?
-
0
-
0 1
2
-
0 1
2
0
1
2
0
1
2
-
Compilation fails
Answer: B Explanation:
table.length is 3. So the do-while loop will run 3 times with ii=0, ii=1 and ii=2. The second while statement will break the do-loop when ii = 3.
Note:The Java programming language provides ado-whilestatement, which can be expressed as follows:
do { statement(s)
} while (expression);
Question No: 66
Given the code fragment:
System.out.println(2 4 * 9 – 3); //Line 21
System.out.println((2 4) * 9 – 3); // Line 22
System.out.println(2 (4 * 9) – 3); // Line 23
System.out.println(2 4 * (9 – 3)); // Line 24
System.out.println((2 4 * 9) – 3); // Line 25 Which line of codes prints the highest number?
-
Line 21
-
Line 22
-
Line 23
-
Line 24
-
Line 25
Answer: B
Explanation: The following is printed: 35
51
35
26
35
Question No: 67
An unchecked exception occurs in a method dosomething()
Should other code be added in the dosomething() method for it to compile and execute?
-
The Exception must be caught
-
The Exception must be declared to be thrown.
-
The Exception must be caught or declared to be thrown.
-
No other code needs to be added.
Answer: D Explanation:
Because the Java programming language does not require methods to catch or to specify unchecked exceptions (RuntimeException,Error, and their subclasses), programmers may be tempted to write code that throws only unchecked exceptions or to make all their exceptionsubclasses inherit fromRuntimeException. Both of these shortcuts allow programmers to write code without bothering with compiler errors and without bothering to specify or to catch anyexceptions. Although this may seem convenient to the programmer, it sidesteps theintent of thecatchorspecifyrequirement and can cause problems for others using your classes.
Question No: 68
Given:
Which approach ensures that the class can be compiled and run?
-
Put the throw new Exception() statement in the try block of try – catch
-
Put the doSomethingElse() method in the try block of a try – catch
-
Put the doSomething() method in the try block of a try – catch
-
Put thedoSomething() method and the doSomethingElse() method in the try block of a try – catch
Answer: A Explanation:
We need to catch the exception in the doSomethingElse() method. Such as:
private static void doSomeThingElse() { try {
throw new Exception();} catch (Exception e)
{}
}
Note: One alternative, but not an option here, is the declare the exception in doSomeThingElse and catch it in the doSomeThing method.
Question No: 69
Given:
public class Test {
public static void main(String[] args) { int arr[] = new int[4];
arr[0] = 1;
arr[1] = 2;
arr[2] = 4;
arr[3] = 5; int sum = 0; try {
for (int pos = 0; pos lt;= 4; pos ) { sum = sum arr[pos];
}
} catch (Exception e) { System.out.println(quot;Invalid indexquot;);
}
System.out.println(sum);
}
}
What is the result?
-
12
-
Invalid Index 12
-
Invalid Index
-
Compilation fails
Answer: B
Explanation: The loop ( for (int pos = 0; pos lt;= 4; pos ) { ), it should be pos lt;= 3, causes an exception, which is caught. Then the correct sum is printed.
Question No: 70
Which three statements are benefits of encapsulation?
-
Allowsa class implementation to change without changing t he clients
-
Protects confidential data from leaking out of the objects
-
Prevents code from causing exceptions
-
Enables the class implementation to protect its invariants
-
Permits classes to be combined into the same package
-
Enables multiple instances of the same class to be created safely
Answer: A,B,D
100% Ensurepass Free Download!
–Download Free Demo:1z0-803 Demo PDF
100% Ensurepass Free Guaranteed!
–1z0-803 DumpsEnsurePass 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 HOT CATEGORY!HOT EXAM!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 -