Sail E0 Webinar
Question


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);
}
}
Options:
A .  a
B .  b
C .  c
D .  abc
Answer: Option D

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 ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers