Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

Isam Al-Abbasi
Isam Al-Abbasi
2,058 Points

Still confused about the use of Static keyword!! please explain furthermore.

I didn't get the part when Craig was explaining what the static method does and then he referred to the Integer.parseInt and he said it's start making sense now!! I was like "not to me it didn't :D" I'm also still confused about when do I use () or ; or {} after each line of code?

2 Answers

Hi,

To be honest with you at the beginning I was also confused. So it is normal. But now I understand it as following. If you had two methods:

public int add(int a, int b){ return a+b; }

public static int add(int a, int b){ return a+b; }

Let's assume, that they are both contain in Example class in order to run first method without static keyword, you would need to create object of this class (Example exp = new Example()) and then use exp.add(5,2), in second definition of this method you don't need to create object of this class, instead of this you can write Example.add(5,2). Same thing will be with fields.

Is it more clear for you now?

Craig Dennis correct me if I am wrong.

Thanks

Isam Al-Abbasi
Isam Al-Abbasi
2,058 Points

Thank you Piotr, well explained. I think I need to keep watching the videos and keep practicing and I hope things will become more clear by then.

I appreciate taking the time to answer my question.

Kristopher Van Sant
Kristopher Van Sant
Courses Plus Student 18,830 Points

Hey Isam Al-Abbasi! I'm so happy to see that Piotr was able to help you and answer your question! Why not go ahead and mark is his answer as "Best Answer". This will also help other students, who might have the same question as you, see that an answer was provided that helped you, meaning it will most likely help them too. Happy coding! And keep up the awesome work. :)

Isam Al-Abbasi
Isam Al-Abbasi
2,058 Points

Hello Kristopher Van Sant thanks for reminding me as I forgot to do so. It really was a big help.

Happy coding for all of us :)