Home / Java Programming / Java.lang Class :: Discussion

Discussion :: Java.lang Class

  1. What will be the output of the program?

    String a = "newspaper"; a = a.substring(5,7); char b = a.charAt(1); a = a + b; System.out.println(a); 

  2. A.
    apa
    B.
    app
    C.
    apea
    D.
    apep

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    Both substring() and charAt() methods are indexed with a zero-base, and substring() returns a String of length arg2 - arg1.


Be The First To Comment