Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In java language Question 1 What is output by the following code? (Assume there

ID: 3684861 • Letter: I

Question

In java language

Question 1

What is output by the following code? (Assume there is a classNegativeNumberException defined in this package.)

public static void main(String[] args) {
try {

int num = 99;
sampleMethod(num);

} catch(Exception ex) {

System.out.print("CaughtMain");

}
}
public static void sampleMethod(int n) throws Exception {
try {
if(n>0)

throw new Exception();

else if(n<0)

throw new NegativeNumberException();

else

System.out.print("Good");

System.out.print("InSample");
}catch(NegativeNumberException ex) {

System.out.print("CaughtSample");

} finally {

System.out.print("InFinal");

}
System.out.print("AfterFinal");
}
}

Answer: ?????

Question 2:

What is output if the following line in main is replaced?

int num = -99;

Answer:

Question 3

What is output if the following line in main is replaced?

int num = 0;

Answer:

Question 4

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;

            }

Select one or more:

a. statement1

b. statement2

c. statement3

d. statement4

e. statement5

f. statement6

g statement7

h. statement8

i. statement9

j. statement10

k. statement11

l. statement12

m. statement13

n. statement14

o. statement15

Question 5

Which statements will execute if an exception of type ExceptionS is thrown before statement11 in methodB?

Select one or more:

a. statement1

b. statement2

c. statement3

d. statement4

e. statement5

f. statement6

g statement7

h. statement8

i. statement9

j. statement10

k. statement11

l. statement12

m. statement13

n. statement14

o. statement15

Question 6

Which statements will execute if an exception of type ExceptionR is thrown before statement11 in methodB?

a. statement1

b. statement2

c. statement3

d. statement4

e. statement5

f. statement6

g statement7

h. statement8

i. statement9

j. statement10

k. statement11

l. statement12

m. statement13

n. statement14

o. statement15

Question 7

Which statements will execute if an exception of type ExceptionQ is thrown before statement11 in methodB?

a. statement1

b. statement2

c. statement3

d. statement4

e. statement5

f. statement6

g statement7

h. statement8

i. statement9

j. statement10

k. statement11

l. statement12

m. statement13

n. statement14

o. statement15

Question8

Which statements will execute if an exception of type ExceptionC is thrown before statement11 in methodB?

a. statement1

b. statement2

c. statement3

d. statement4

e. statement5

f. statement6

g statement7

h. statement8

i. statement9

j. statement10

k. statement11

l. statement12

m. statement13

n. statement14

o. statement15

Explanation / Answer

1. Output: InFinalCaughtMain
2. Output: CaughtSampleInFinalAfterFinal
3. Output: GoodInSampleInFinalAfterFinal
4. Following statements will execute if no exceptions are thrown
   statement1
   statemen6
   statement11
   statement14
   statement15
   statement7
   statement9
   statement10
   statement2
   statement4
   statement5
  
5. statement1
   statemen6
   statement12
   statement14
   statement15
   statement7
   statement9
   statement10
   statement2
   statement4
   statement5
  
6.   statement1
   statemen6
   statement14
   statement15
   statement7
   statement9
   statement10
   statement2
   statement4
   statement5
  
7.   statement1
   statemen6
   statement14
   statement15
   statement7
   statement9
   statement10
   statement2
   statement4
   statement5
  
8.   statement1
   statemen6
   statement14
   statement15
   statement7
   statement9
   statement10
   statement2
   statement4
   statement5
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote