Explain the correct answer of a challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Explain the correct answer of a challenge

Please, I would like to understand what I wrong in a challenge... Not only know the correct answer. Thank you

15th Apr 2019, 5:27 PM
Stefano B
Stefano B - avatar
12 Answers
+ 6
Stefano B You have two integers (lets ignore protected because it has no effect on the output) int x and int y. Now you create an object t. But nothing more. Means x and y are 0. So if you print t.x + t.y then you got 0. Test t = new Test(); t.x = 2; t.y = 5; System.out.println(t.x + t.y); //output 7 Hope this helps. Here is a link where the keywords public, private, protected are explained. https://stackoverflow.com/questions/215497/what-is-the-difference-between-public-protected-package-private-and-private-in
15th Apr 2019, 8:10 PM
Denise Roßberg
Denise Roßberg - avatar
+ 5
Stefano B after the challenge you can scroll down and click on the *show correct answer* to see the questions you got wrong and right.
15th Apr 2019, 5:53 PM
Jella
Jella - avatar
+ 4
Here is a code where you can see it: https://code.sololearn.com/cU0ywCH5dPIN/?ref=app
15th Apr 2019, 8:14 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Let me call a buddy of mine who's an expert in Java. Denise Roßberg
15th Apr 2019, 7:34 PM
Diego
Diego - avatar
+ 3
Thank you so much Diego
15th Apr 2019, 7:57 PM
Stefano B
Stefano B - avatar
+ 2
You can ask for help in this section. Include the question and what you don't understand.
15th Apr 2019, 6:44 PM
Diego
Diego - avatar
+ 1
Ok thank you. Can I post a screenshoot?
15th Apr 2019, 7:05 PM
Stefano B
Stefano B - avatar
+ 1
Yes, and don't forget to specify the programming language.
15th Apr 2019, 7:08 PM
Diego
Diego - avatar
+ 1
In java, the question was to find output of this code: Class Test{ protected int x, y; } Class main{ public static void main(String args[]) { Test t=new Test(); System.out.println(t.x + t.y); } } Output: 0
15th Apr 2019, 7:27 PM
Stefano B
Stefano B - avatar
+ 1
Koder King🐱 yes I know how to see correct answer but sometime the question is: why??? Maybe very good if the answer are more than only a number.
16th Apr 2019, 9:50 AM
Stefano B
Stefano B - avatar
+ 1
Denise Roßberg thank you, very exaustive.
16th Apr 2019, 9:52 AM
Stefano B
Stefano B - avatar
+ 1
Stefano B Your welcome. :)
16th Apr 2019, 1:15 PM
Denise Roßberg
Denise Roßberg - avatar