Question: 5) Which line(s) below opens MyFile.txt allows to append data to its existing contents? A) File fwriter = new File(MyFile.txt); FileWriter outFile = new FileWriter(fwriter,

5) Which line(s) below opens MyFile.txt allows to append data to its existing contents?

A) File fwriter = new File("MyFile.txt");

FileWriter outFile = new FileWriter(fwriter, true);

B) FileWriter outfile = new FileWriter(true, "MyFile.txt");

C) File fwriter = new File("MyFile.txt");

FileWriter outFile = new FileWriter(fwriter);

D) File outfile = new File("MyFile.txt", true);

6) A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event.

A) default exception handler B) error message C) exception handler D) exception

7) In a try/catch construct, after the catch statement is executed

A) the program returns to the statement following the statement in which the exception occurred

B) the program resumes at the statement that immediately follows the try/catch construct

C) the program terminates

D) the program resumes at the first statement of the try statement

8) An exceptions default error message can be retrieved using this method.

A) getErrorMessage() B) getDefaultErrorMessage()

C) getMessage() D) getDefaultMessage()

9) In the following code, assume that inputFile references a Scanner object that has been successfully used to open a file:

double totalIncome = 0.0;

while (inputFile.hasNext())

{

try

{

totalIncome += inputFile.nextDouble();

}

catch(InputMismatchException e)

{

System.out.println("Non-numeric data encountered " +

"in the file.");

inputFile.nextLine();

}

finally

{

totalIncome = 35.5;

}

}

What will be the value of totalIncome after the following values are read from the file?

2.5

8.5

3.0

5.5

abc

1.0

A) 35.5 B) 75.0 C) 0.0 D) 19.5

10) Why does the following code cause a compiler error?

try

{

number = Integer.parseInt(str);

}

catch (IllegalArgumentException e)

{

System.out.println("Bad number format.");

}

catch (NumberFormatException e)

{

System.out.println(str + " is not a number.");

}

A) Because you can have only one catch clause in a try statement.

B) Because the Integer.parseInt method does not throw a NumberFormatException.

C) Because the Integer.parseInt method does not throw an IllegalArgumentException.

D) Because NumberFormatException inherits from IllegalArgumentException. The code should handle NumberFormatException before IllegalArgumentException.

please just prove the correct answer without explaination. thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!