Question: Could someone help me with this please? Thanks public class Oops { // Instatatiate a RuntimeException here. RuntimeException x; public Oops() { // Instatatiate a

Could someone help me with this please? Thanks

public class Oops { // Instatatiate a RuntimeException here. RuntimeException x; public Oops() { // Instatatiate a RuntimeException here. x = new RuntimeException("Instantiated in the constructor"); } public void m1() { m2(); } public void m2() { // Instatatiate a RuntimeException here. x = new RuntimeException("Instantiated in m2"); m3(); } public void m3() { m4(); } public void m4() { // Instatatiate a RuntimeException here. x = new RuntimeException("Instantiated in m4"); throw x; } public static void main(String[] args) { // Instatatiate a RuntimeException here. new Oops().m1(); } }

Do not undo the previous change.

Compile and run the class as is. 1) What is the exception message you get? Include the stack trace in the answer.

Comment out the instantiation on line 27. Compile and run the class again. 2) What is the exception message you get now? Include the stack trace

Comment out the instantiation on line 17. Compile and run the class again. 3) What is the exception message you get now? Include the stack trace

Comment out the instantiation on line 8. Instantiate the exception within main. This will require a bit more work than adding a single line of code.* Do not make the field static at this time. Compile and run the class again. 4) What is the exception message you get now? Include the stack trace in the answer.

* The issue is that the field is not static, while main is. Notice that the method is also not static. To call the method, we use a reference to an Oops instance. You will need to change the code so that the reference can be used twice: once to bind a newly instantiated exception instance to the non-static field, x, and once to call the non-static method, m1.

Comment out the instantiation in main. Update the field declaration on line 4 to include an instantiation of the runtime exception. Compile and run the class again. 5) What is the exception message you get now? Include the stack trace in the answer.

Update the field declaration to be static. Keep the instantiation of the exception in the field declaration. Compile and run the class again. 6) What is the exception message you get now? Include the stack trace in the answer.

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!