JAVA 1. Use the code below to answer the next 5 questions. Which statements will
ID: 3685110 • Letter: J
Question
JAVA 1. Use the code below to answer the next 5 questions. Which statements will execute if no exceptions are thrown?
public static void main(String[] args) {
try {
statement1;
methodA();
statement2;
} catch (ExceptionQ ex) {
statement3;
} finally {
statement4;
}
statement5;
}
public static void methodA() {
try {
statemen6;
methodB();
statement7;
} catch (ExceptionR ex) {
statement8;
} finally {
statement9;
}
statement10;
}
public static void methodB() {
try {
statement11;
} catch (ExceptionS ex) {
statement12;
} catch (ExceptionT ex) {
statement13;
} finally {
statement14;
}
statement15;
}
2.Which statements will execute if an exception of type ExceptionS is thrown before statement11 in methodB?
3..Which statements will execute if an exception of type ExceptionR is thrown before statement11 in methodB?
4.Which statements will execute if an exception of type ExceptionQ is thrown before statement11 in methodB?
5.Which statements will execute if an exception of type ExceptionC is thrown before statement11 in methodB?
6.
Write a method to read in two pieces of information from a user (using a Scanner object).
First, read in the name of a file. Using this name, create a file object to be returned from the method.
Use exception handling so that the code will compile.
Second, read in the number of lines in the file and store this in an int.
Use exception handling to account for the user typing a non-number.
If the user enters in a proper number, print it back out to the user before returning the file.
Note: you are not opening or reading from the file or checking the number- you are just creating the File object and returning it (presumably to be dealt with elsewhere).
Here is the method header- use this exact header with no changes:
public File readFileAndLength()
Explanation / Answer
Multiple Questions : Answering 1 & 2 :
1.
statement1;
statemen6;
statement11;
statement14;
statement15;
statement7;
statement9;
statement10;
statement2;
statement4;
statement5;
2.
statement1;
statemen6;
statement12;
statement14;
statement15;
statement7;
statement9;
statement10;
statement2;
statement4;
statement5;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.