0

What if I don't declare a Variable of a specific data type as static and try to access it from a static method say main()?

https://code.sololearn.com/cKQqtBfgMq61/?ref=app

1st Dec 2018, 1:50 PM
Subrata Karmakar
Subrata Karmakar - avatar
9 ответов
+ 3
every reference has it's own copy of non-static variable Whereas static variables are shared A cording to your program, reference variable e1,e2,and e3 has it's own copy of non-static variable 'a' There will be only one copy of static variable 'b' which is shared among e1,e2,and e3
1st Dec 2018, 2:15 PM
Rishi Anand
Rishi Anand - avatar
+ 3
Yes....because it's a non-static variable
1st Dec 2018, 4:37 PM
Rishi Anand
Rishi Anand - avatar
+ 3
In this you are not getting your output because you are using short-circuit operator && Use & instead of && and you will get your desired output https://www.sololearn.com/Discuss/1600030/?ref=app
1st Dec 2018, 5:52 PM
Rishi Anand
Rishi Anand - avatar
+ 1
Do you know how post increment and pre increment operator works?
1st Dec 2018, 5:06 PM
Rishi Anand
Rishi Anand - avatar
+ 1
Thanks a lot.....
1st Dec 2018, 6:10 PM
Subrata Karmakar
Subrata Karmakar - avatar
0
That means value of a gets incremented by 1 only once no matter how many times I access the variable....
1st Dec 2018, 4:35 PM
Subrata Karmakar
Subrata Karmakar - avatar
1st Dec 2018, 4:43 PM
Subrata Karmakar
Subrata Karmakar - avatar
0
Please explain this one to me.....I am thoroughly confused....Wish I had justified the output by modifying the code but I didn’t.....
1st Dec 2018, 4:46 PM
Subrata Karmakar
Subrata Karmakar - avatar
0
Yup....definitely.......pre increment operator gets the value of the variable incremented first and then assigns it to the variable.....post increment operator does the opposite.....
1st Dec 2018, 5:22 PM
Subrata Karmakar
Subrata Karmakar - avatar