How many String objects are instantiated by the following code segment (not including the literals)? String s1, output; s1 = "hello"; output = "\nThe string reversed is: " ; for (int i = s1.length() - 1; i >= 0; i--) output += s1.charAt(i) + " " ;

Respuesta :

Answer:

Two

Explanation:

In object oriented programming, instantiation of a class means an object is created from a class template. To instantiate a class, the syntax is as below:

ClassName objectName;

In this case, we have a program statement:

String s1, output;

The String is a class. s1 and output are the variables of the objects created from the String class.  Therefore s1 and output are two string objects instantiated from the String class.