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

User Bmalicoat
by
3.3k points

1 Answer

2 votes

Answer:

Two

Step-by-step 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.

User Daniel Gabriel
by
4.0k points