+ 2

I just started learnig java, and my first try with methods doesnt work, but i dont understand whats wrong, could sb. help ?

Java Problem

7th Jan 2020, 8:10 PM
Pjascha D
16 Antworten
+ 4
Jnn it is just that the static members were also given the privilege to be invoked without the object of the class. We are all learning here so don't say sorry because it's completely fine to make mistakes.
8th Jan 2020, 11:21 AM
Avinesh
Avinesh - avatar
+ 3
Jnn The static methods can be invoked using an object of the class as well, you seem to disagree with that in your 2nd point. Just letting you know👍
8th Jan 2020, 2:06 AM
Avinesh
Avinesh - avatar
+ 2
1) The entry point of your code is the public static void main(String[] args) function. 2) if you call a function without using an instance of a class it needs to be static (can be called by the class not the object of a class) 3) all attributes or functions called by a static function also need to be static
7th Jan 2020, 8:22 PM
Jnn
Jnn - avatar
+ 2
4) In the function where you print hello world you don't need the String[] args parameter. Its only used in the main function to access parameters when running the code. But that is often not used.
7th Jan 2020, 8:26 PM
Jnn
Jnn - avatar
+ 2
Avinesh Im sry you are correct 😊
8th Jan 2020, 11:04 AM
Jnn
Jnn - avatar
+ 2
Now that the issue is resolved, maybe you need to prefix your question with [Solved].
9th Jan 2020, 12:26 PM
Sonic
Sonic - avatar
+ 1
Could you post your code here?
7th Jan 2020, 8:12 PM
Jnn
Jnn - avatar
7th Jan 2020, 8:15 PM
Pjascha D
+ 1
Okay thanks alot =) What does this static before the string changes? Why doesent it work without it?
7th Jan 2020, 8:22 PM
Pjascha D
+ 1
Really thank you =)
7th Jan 2020, 8:24 PM
Pjascha D
+ 1
Because that is an attribute. If you have a class every object has its own. But you use this attribute in a static function only called by the class so this attribute needs to be static too
7th Jan 2020, 8:28 PM
Jnn
Jnn - avatar
+ 1
Mirielle🐶 Not all methods need to be static if you create an instance of this class in the main method you can call non static methods with this instance
7th Jan 2020, 8:56 PM
Jnn
Jnn - avatar
+ 1
Practice in Android studio software which is only one best option for java.
8th Jan 2020, 11:49 AM
Abhishek nirwan
Abhishek nirwan - avatar