Accenture Java Programming Practice Question
Predict the output class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); System.out.println(s); } }Answer options
A
a
B
b
C
abc
D
c A character array is initialized with 'a', 'b' and 'c' and the array reference is chars. Printing this reference will output ab
E
A "new" string object is initialized with this reference and this object is referred by "s". Printing this reference will output ab
Correct answer: a
Explanation
Correct answer: a.