What is the result?

Given the code fragment:

What is the result?
A. Element 0
Element 1
B. Null element 0
Null element 1
C. Null
Null
D. A NullPointerException is thrown at runtime.

Download Printable PDF. VALID exam to help you PASS.

5 thoughts on “What is the result?

  1. D
    public static void main(String[] args) {
    String array[] = new String[2];
    int idx=0;
    for(String s:array){array[idx].concat(“Element”+idx);// throw java.lang.NullPointerException
    idx++;}
    for(idx=0;idx<array.length;idx++){
    System.out.println(array[idx]);//null null
    }
    }
    so result D

  2. D
    public static void main(String[] args) {
    String array[] = new String[2];
    int idx=0;
    for(String s:array){array[idx].concat(“Element”+idx);// throw java.lang.NullPointerException
    idx++;}
    for(idx=0;idx<array.length;idx++){
    System.out.println(array[idx]);//null null
    }
    }
    so result D

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.