Java: How many objects are created in the code?

How many objects are created in the following code?

String a, b, c;
a = "1234";
b = a;
c = a + b;

I was told that the answer 2is because only a and b indicate their own data.

ccreated only when using aand b. However, is not declaring a variable declaration a variable creation ? Is this a vague question? I said 3.

+4
source share
2 answers

a = "abcd"creates an object Stringand initializes it with the value "abcd". So one object

b = a b , a, a + b , c. ,

+3

, 2. b = a, a b. , , a b . .

0

All Articles