[Free] 2018(Jan) EnsurePass Examcollection Oracle 1z0-803 Dumps with VCE and PDF 61-70

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?

  1. – 6

  2. – 4

  3. – 5

  4. 5

  5. 4

  6. 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?

  1. 8

  2. 9

  3. 11

  4. 10

  5. 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:

Ensurepass 2018 PDF and VCE

Which two are possible outputs?

Ensurepass 2018 PDF and VCE

  1. Option A

  2. Option B

  3. Option C

  4. 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?

  1. AssertionError, ArrayIndexOutOfBoundsException, ArithmeticException

  2. AssertionError, IOError, IOException

  3. ArithmeticException, FileNotFoundException, NumberFormatException

  4. FileNotFoundException, IOException, SQLException

  5. 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:

    Ensurepass 2018 PDF and VCE

    What is the result?

    1. 0

    2. 0 1

      2

    3. 0 1

      2

      0

      1

      2

      0

      1

      2

    4. 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?

    1. Line 21

    2. Line 22

    3. Line 23

    4. Line 24

    5. 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?

    1. The Exception must be caught

    2. The Exception must be declared to be thrown.

    3. The Exception must be caught or declared to be thrown.

    4. 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:

    Ensurepass 2018 PDF and VCE

    Which approach ensures that the class can be compiled and run?

    1. Put the throw new Exception() statement in the try block of try – catch

    2. Put the doSomethingElse() method in the try block of a try – catch

    3. Put the doSomething() method in the try block of a try – catch

    4. 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?

    1. 12

    2. Invalid Index 12

    3. Invalid Index

    4. 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?

    1. Allowsa class implementation to change without changing t he clients

    2. Protects confidential data from leaking out of the objects

    3. Prevents code from causing exceptions

    4. Enables the class implementation to protect its invariants

    5. Permits classes to be combined into the same package

    6. 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!
    Download 2018 EnsurePass 1z0-803 Full Exam PDF and VCE

    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

Leave a Reply

Your email address will not be published. Required fields are marked *