+ 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
12 ответов
+ 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
+ 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.
+ 4
Here is a code where you can see it:
https://code.sololearn.com/cU0ywCH5dPIN/?ref=app
+ 3
Let me call a buddy of mine who's an expert in Java.
Denise Roßberg
+ 3
Thank you so much Diego
+ 2
You can ask for help in this section. Include the question and what you don't understand.
+ 1
Ok thank you. Can I post a screenshoot?
+ 1
Yes, and don't forget to specify the programming language.
+ 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
+ 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.
+ 1
Denise Roßberg thank you, very exaustive.
+ 1
Stefano B Your welcome. :)