0

Public static method vs Static method

what is the difference when you declare a method like this Public static void name(){ -------------- } or this static void name(){ ------------ }

8th Nov 2020, 8:58 AM
Anaxagoras Anaxagorou
Anaxagoras Anaxagorou - avatar
3 Réponses
+ 1
No access modifier means package private. So only classes which are in this package can access this method. With public all classes can access this method which is sometimes not usefull if this method should not be called from outside this package.
8th Nov 2020, 9:07 AM
Jnn
Jnn - avatar
+ 2
Anaxagoras Anaxagorou public static void name(){ } In a simple word. If you use public keyword with a static method that means you are able to access this method from anywhere in your project or program. No restriction at all. //All package, sub packages can access this. You can call this method by using (class_name).(method_name) From anywhere. static void name(){ } // If you are method without any access modifier like publication, private and protected so by default this method will be package private. That means you can access this method only in same package. And you can't access this method outside this package.
8th Nov 2020, 12:47 PM
P‚ąÜWAN M‚ąÜURY‚ąÜ
P‚ąÜWAN M‚ąÜURY‚ąÜ - avatar
0
thank you guys
16th Nov 2020, 11:26 AM
Anaxagoras Anaxagorou
Anaxagoras Anaxagorou - avatar