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

Java Homework! Using the provided code consider the following 3 questions: What

ID: 3686047 • Letter: J

Question

Java Homework!

Using the provided code consider the following 3 questions:

What is the output of the following code?

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

int num = -99;

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

int num = 0;

(NOTE: 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");
}
}

Explanation / Answer

num = 99
InFinalCaughtMain
num = -99
CaughtSampleInFinalAfterFinal
num = 0
GoodInSampleInFinalAfterFinal

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