Menu
Topics Index
...
`

GetChars


If you need explanation Read this topic

If you need Answer Take test on this topic

GetChars
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, 6);
        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 is A since  salman of data variable s h l replaced by o a l and prints sohali

Posted by Bharath Yelchuri    2014-06-20 14:51:42


Ans is a ...the first 6 characters in the string is replaced by contents of array using getchars so the answer is Sohail Khan is an Indian actor

Posted by Badam Swathi    2014-06-20 14:55:57


option a is correct...as it replaces salman with sohail..prints the remaining strng as it is

Posted by Vijay Kumar    2014-06-20 14:57:19


Answer Is A : Because when getchars function start it replaces salman to sohail (only 6 characters change) rest is same.

Maximum 6 characters change only.

Posted by Kirti Kumar    2014-06-21 03:48:14


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

Posted by Merit Campus    2014-06-23 04:40:45


© meritcampus 2019

All Rights Reserved.

Open In App