Question: Based on the following program, find the error, and rewrite the code with no error ( 2 marks ) public class MyClass { public static

Based on the following program, find the error, and rewrite the code with no error (2 marks)
public class MyClass
{
public static void main(String[] args)
{
try
{
String s= null;
int i= s. length();
}
catch (Exception e)
{
System.out.println(1);
}
catch (NullPointerException e)
{
}
System.out.println(2);
}
}
 Based on the following program, find the error, and rewrite the

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!