#If we create multiple objects of the same type, do they share values of their constructor?

1 messages · Page 1 of 1 (latest)

ebon flicker
#

Hello, sorry to disturb you all; does anyone know what is the correct answer? It is the second attempt that I made to this question and I still got it wrong; at first I put the answer as D but it was incorrect so in my second attempt I put it as A thinking that each object has its own constructor so i will be incremented by only one value and will not become 3... can someone explain which answer is correct and why please.

What I mean by "share values" is that, I know that they will have the same default values but consider the diagram where we increment the value of i for each objects created. What's happening here ?

tight abyssBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

am making to ask this question.

ebon flicker
#

I might have an answer, can someone just verify it:

My understanding is that: int i is unique for each object since it doesn't have the key word static while the static int s is shared for all the objects of the class Foo... so each time an object is created, the value of s will be incremented for each object but the value of i will only be one since it depends only on a particular object.... therefore answer is B ?

dire moth
#

correct