Menu
Question Index
...

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);
        }
    }
}


Sohail Khan is an Indian actor
Salman Khan is an Indian actor
Some other output
Runtime Error because java.lang.ArrayIndexOutOfBoundsException
Compilation Error or Runtime Error for some other reason

Doubts

Problems

Topic: getChars() Method In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App