Question: Question 2 [3+5) A. Rewrite the given code such that it handles exceptions and the message Exception handled successfully should be displayed whether an exception

 Question 2 [3+5) A. Rewrite the given code such that it

Question 2 [3+5) A. Rewrite the given code such that it handles exceptions and the message Exception handled successfully" should be displayed whether an exception occurs or not for both divide() and display_namelength() methods. You can only change inside the main function. public class ExceptionTest { public static void main(String[] args) { calculator obj = new calculator(); obj.divide(); obj.display_namelength(); } class calculator { String name = null; int numl; int num2; public calculator() { Scanner input = new Scanner(System.in); System.out.println("Enter the first number"); this.numl = input.nextInt(); System.out.println("Enter the second number"); this.num2 = input.nextInt(); } public void divide () { System.out.println(numl / num2); } public void display_namelength() { System.out.println(name.length()); // name object can be null }

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!