Java Programming
primer-original-v2mediumJava Programming4. Arrays And Stringsprimer-original-v2

Java Programming Practice Question

Predict the output p class String_demo { public static void main(String args[]) { int ascii[] = { 65, 66, 67, 68}; String s = new String(ascii, 1, 3); System.out.println(s); } }

Answer options

A
ABCD
B
ABC
C
CDA
D
BCD An integer array is initialized with values 65, 66, 67 and 68. Its reference is "ascii". A new string object is initialized with this reference such that the elements from index 1 through 3 alone gets copied as "characters". This object is referred by "s". Printing this object will output BCD which are the char-equivalents of 66, 67 and 68.

Correct answer: ABCD

Explanation

Quick AnswerThe correct answer is ABCD because it directly addresses the core logic of Java Programming.

This question has been retained as-is due to its unique context.

Related Java Programming questions

Practice more Java Programming questions

PrimerPrep has independently reviewed practice questions and coding exercises — all free.