Question
class String_demo {
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
System.out.println(s);
}
}
What is the output of this program?
class String_demo {
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
System.out.println(s);
}
}
Answer: Option D
Was this answer helpful ?
String(chars) is a constructor of class string, it initializes string s with the values stored in character
array chars, therefore s contains "abc".
output:
$ javac String_demo.java
$ java String_demo
abc
Was this answer helpful ?
More Questions on This Topic :
Question 7.
Which of these is an oncorrect statement?
....
Submit Solution