Detect if there is any syntax or runtime error for each stat

Detect if there is any syntax or runtime error for each statement of the following program. Please write \"SYNTAX\" for syntax errors, \"RUNTIME\" for runtime errors and \"NO\" for no errors, class person {private String name; int value; person (int x) {value = x;}} public class Test {public static void main (String [] arg) {int [] x = {1, 2, 3, 4}; int y, z\' x [0] = 1; y = 1.0; person p = new person ();//Person p1 = new Person (10);//p1. Name = \"Austin\";//p1. Y = 10;//z - 3/0;//x [5] = 1;//

Solution

SOLUTION

public class Person {
  
   private String name;//valid
   int value;//valid
   //valid
   public Person(int x) {
       value=x;
   }
  

}

Test class

public class Test {
   public static void main(String[] arg) {
       int[] x = { 1, 2, 3, 4 };// valid

       // you have to initialize the local variables
       // local variables means the members/variables which are declared within
       // the method,blocks,loops etc....
       int y, z;// compile time error(you are not get any compile time error
                   // but if you want to access y or z without initializing you
                   // will get compile time error)

       x[0] = 1;// valid

       // this is compile time error cannot convert double to int
       y = 1.0;

       // if we don\'t provide any constructor compiler creates a default
       // constructor
       // if we write parameter constructor in our class compiler ignores to
       // create no-org
       // constructor in this case we get a compile time error must and should
       // pass value while creating constructor

       Person p = new Person();// compile time

       // valid statement
       Person p1 = new Person(10);

       // we cannot access private members outside the class
       // if you want access the private members outside of the class must use
       // setters and getters
       // in this case change visibility to default or other modifiers
       p1.name = \"Austin\";// compile time error

       p1.y = 10;// compile time error (y cannot be resolved or not a field)

       z = 3 / 0;// you are going to get runtime exception
                   // exception in thread main:ArithmeticException

       x[5] = 1;// you are going to get runtime exception
                   // Exception in thread \"main\" java.lang.ArrayIndexOutOfBoundsException
   }

}

 Detect if there is any syntax or runtime error for each statement of the following program. Please write \
 Detect if there is any syntax or runtime error for each statement of the following program. Please write \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site