Question: public interface StackADT { public void push(T element); public T pop(); } and the following Java code fragment: StackADT s = new StackADT(); s.push(hello); s.push(hi);

  • public interface StackADT { public void push(T element); public T pop(); } and the following Java code fragment: StackADT s = new StackADT(); s.push("hello"); s.push("hi"); System.out.println(s.pop());

  • ------------why The above code has compilation errors.----------------

  • String s;

  • String[] arr = new String[5]; try {

  • s = arr[0];

  1. for (int i = 0; i < s.length(); ++i) s = s + arr[i];

    } catch (ArrayIndexOutOfBoundsException e) {

    System.out.println("Invalid index");

    } catch (NullPointerException e) {System.out.println("Null pointer");} catch (Exception e) {System.out.println("Exception");

  2. -------What is printed when the above code is executed? -------why null pointer-----

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!