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(){ ------------ }
3 Respostas
+ 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.
+ 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.
0
thank you guys