In Test1 you have a constructor that takes a String. You call that constructor without the String input. And calling the function setString inside the constructor is redundant if you create an instance with a string name as a parameter.
Looks like you could just delete the constructor in the Stringy class and it will work.
In Test2 I have no idea what you are trying to do. What the output is, is what the output should be. What you expect is harder to say. You have the counter as a static field and are accessing it by creating a new instance, which adds another count to the counter.
Anyway, you set the id to be = to the static field counter which is 0, then you add 1 to the counter. You print id which should be 0, Then you create an instance of Test which adds another count to counter, and print counter which should be 2 by now. Then you create another instance of Test which sets id to be = to counter or 2, and this adds another to counter which makes it 3, print id should be 2. Then you create another instance of Test which makes counter 4, print counter (4). Then create another instance of Test which makes counter = to 5, and sets id = to 4, print id. Create another instance and add another to counter, print counter which would be 6 by now... etc So the output should be
0 set id to 0 print id or (0), then add 1 to counter
2 create a new instance which adds 1 to counter to make 2, print counter or 2
2 new instance which sets id to counter which is 2 print id which is 2, this new instance then adds 1 to counter to make 3
4 new instance sets id to counter or 3, adds 1 to counter to make 4, print counter which is 4
4 new instance sets id to counter (4), then add 1 to counter, print id (4) counter is now 5
I think it would be better to ask how to write a piece of code that behaves a particular way.