+ 3

Java public static void order

public class Program { public void static main(String[] args) { System.out.println("hi"); } } this gives an error while public class Program { public static void main(String[] args) { System.out.println("hi"); } } this works perfectly fine so does that means the order of public static void matters?? bcoz i thought i didnt.

17th Jun 2020, 6:31 PM
Abdul Majeed Faraz
Abdul Majeed Faraz - avatar
5 Réponses
+ 8
As the error message said, return-type required. In a method signature (and definition), scope and access definition comes first, and return type specifier should be written nearest to the method name. `static` is unknown as return type, it is an access modifier. So `void` naturally be the return type for that sample, and should be placed near by the method name to define the method return type.
17th Jun 2020, 6:43 PM
Ipang
+ 2
oh thanks I understand now .
17th Jun 2020, 6:44 PM
Abdul Majeed Faraz
Abdul Majeed Faraz - avatar
+ 2
in java everything must be inside class public means this class is public everyone can access it static means this works without creating an object of the class void means it doesnt returns anything
6th Jul 2020, 9:16 AM
Abdul Majeed Faraz
Abdul Majeed Faraz - avatar
+ 1
Hello, I don't know what's the meaning of " class, public, static , void,main(),string,args ". can anybody explain these terms crystal clear? And also i don't know why they written in such a order? And I read the tutorials but I didn't understand.
29th Jun 2020, 2:12 PM
siva sai kiran
siva sai kiran - avatar
+ 1
ask ur question on discuss other people with more knowledge willl help you
6th Jul 2020, 9:17 AM
Abdul Majeed Faraz
Abdul Majeed Faraz - avatar