0

why have we use public static void instead of public void?

Also can anyone describe the part by part of output line statement system.out.printin("Hello World")

25th Sep 2016, 8:53 AM
Goku San
Goku San - avatar
6 Réponses
+ 2
The static keyword means that you don't need to create an object of the class to be able to use the method. And it's println (lowercase L), not printin.
25th Sep 2016, 9:07 AM
Zen
Zen - avatar
0
Public static void lets you to access method from out of your class or even package without creating object of class it belongs to! So why we have to use is dependent to what type of access we need, for example main method is called by runtime environment, not through any of our own code to run for first time so it requires direct access and we must define it as public static unless your main method is unaccessible and program doesnt runs! Otherwise its your own choice
25th Sep 2016, 6:01 PM
Sijan Maharjan
Sijan Maharjan - avatar
0
System is the class defined under package java.lang which is imported by default!! out is the static object of class PrintStream defined under class System, so it is being accessed directly using classname, and prinln() is method under PrintStream class which is accessed through static object out in order to print the data you passed as parameter over the console screen!
25th Sep 2016, 6:08 PM
Sijan Maharjan
Sijan Maharjan - avatar
0
More like the JVM can't access your code so without the static keyword, nasty errors will pop out.
26th Sep 2016, 2:59 PM
Iam Anonymous
Iam Anonymous - avatar
- 1
ohk... without static it would not execute?
25th Sep 2016, 9:10 AM
Goku San
Goku San - avatar
- 1
because its rules
26th Sep 2016, 10:18 AM
Abhishek