Menu
Topics Index
...
`

GetChars2160


If you need explanation Read this topic

If you need Answer Take test on this topic

GetChars2160
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(0, data.length(), array, 0);
        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.

the String data is copied into the char array[] through the method data.getChars(sourceBegin,sourceEnd,Destination,DestinationBegin), therefore by displaying each character element of the array would result in the displaying of the same content that is existing is String data..... Therefore Option B is the answer

Posted by Kittu Manoj    2014-01-21 13:01:33


array[] first gets Sohail into it.
data.getChars will override the contents of array with the contents in 'data' string. So, array will also have "Salman Khan is an Inidan actor" at the end.
Answer is B

Posted by Sowmya Vepa    2014-01-21 15:14:47


Congratulations Kittu Manoj. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-22 04:03:03


© meritcampus 2019

All Rights Reserved.

Open In App