What will be the output of the following Java program?

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

1 thought on “What will be the output of the following Java program?”

  1. 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:
    $ javac String_demo.java
    $ java String_demo
    abc

Leave a Comment