What will be the output of the following Java program? [code] class String_demo { public static void main(String args[])

Phương Linh

New member
What will be the output of the following Java program?
Code:
    class String_demo 
    {
        public static void main(String args[])
        {
            char chars[] = {'a', 'b', 'c'};
            String s = new String(chars);
            System.out.println(s);
        }
   }
A. a
B. b
C. c
D. abc
 
Answer: d
Explanation: 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:
Code:
$ javac String_demo.java
$ java String_demo 
abc
 

Tìm kiếm

Back
Top