Menu
Topics Index
...
`

GetChars2162


If you need explanation Read this topic

If you need Answer Take test on this topic

GetChars2162
What will be the output of the following program?
public class Actor {
    public static void main(String[] args) {
        String data = "Salman Khan is an Indian actor";
        char array[] = new char[data.length()];
        array[0] = 'S';    array[1] = 'o';
        array[2] = 'h';    array[3] = 'a';
        array[4] = 'i';    array[5] = 'l';
        data.getChars(6, data.length(), array, 7);
        for (char element : array) {
            System.out.print(element);
        }
    }
}

A. Sohail Khan is an Indian actor
B. Salman Khan is an Indian actor
C. Some other output 
D. Runtime Error because java.lang.ArrayIndexOutOfBoundsException 
E. Compilation Error or Runtime Error for some other reason 
Topic: getChars() Method In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans d: exception occurs while executing as  array index goes out of bound in getChars()

Posted by Manasa Jyothi Sree    2014-06-10 14:50:14


ans d: array out of bound index occurs in getchars() in line 8
bcz getchars() 2nd argument require index one past the desired string
here v have kept data.length() instead v shld keep data.length()-1

Posted by Pooja Singh    2014-06-10 15:03:17


Congratulations Manasa Jyothi Sree. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-11 04:00:21


© meritcampus 2019

All Rights Reserved.

Open In App