+ 1
Please explain this code again
why we are using id=i, necessarily and why we are making the b object?
3 RĂ©ponses
+ 7
Nishtha
Maybe you were referring to thisđ
Kindly check the comments of the code below.. hope you'll understand..
https://code.sololearn.com/cna9v7jS5wFd/?ref=app
+ 2
Looks like you asked this question while refering to a specific lesson on sololearn java course.
This is Q&A discuss section and it is another section of sololearn's app/website and is not linked to any perticular lesson.
in order to make this question complete, kindly add all the necessary details (including the code) in the question description.
+ 1
May be your reffering this below link.. But for clarity share link like this here...
https://www.sololearn.com/learn/Java/2173/
There id is Robot Class data property,. You are assigning by constructor a value which is passed.
If you remove that, Id value remain 0 in the next print statement..
Next Brain class is inner class and if we want invoke it's its function 'think', we know we can call methods by class or an object. Since it is instance method, (not static) we shloud call it by an object so first we have to create an object so that's why b object is created and invoked the method 'think'.
Here if you remove id=i (previous) then you get output " 0 is thinking." With id=I, now output is 1 " is thinking.". Hope it helps...