+ 1

Explain its output nd working

This is from the challenge of sololearn Although I answered it correctly but not quite satisfied with it's logic so expalin me plz https://code.sololearn.com/ckOX70Zr6JmR/?ref=app

7th Aug 2019, 2:56 PM
Ayush Pandey
Ayush Pandey - avatar
5 Respostas
+ 9
https://code.sololearn.com/W2LnAYam75y4/?ref=app
7th Aug 2019, 5:50 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 4
Thank u D_Stark and ~ swim ~
7th Aug 2019, 3:23 PM
Ayush Pandey
Ayush Pandey - avatar
+ 3
The static variable x belongs to the class this is why you can use it in your program without having to create an object to access it, u just use the class name. int x = 2; // this is not used int y =1; Program.x ⬅️ =3 Program.x+y ⬅️ =4
7th Aug 2019, 3:21 PM
D_Stark
D_Stark - avatar
+ 3
~ swim ~ I know but it triggers me 😁
7th Aug 2019, 4:02 PM
D_Stark
D_Stark - avatar
+ 2
Ayush Pandey no probs. Also this in your code.. System.out.print(Program .x+y); //There shouldn't be a gap between the class and its static variable, it should look like this all together 👍 Program.x+y
7th Aug 2019, 3:47 PM
D_Stark
D_Stark - avatar