+ 2
What is the difference between static and public in java ??
3 ответов
+ 5
They are completely different.
public is an access modifier that indicates that a function or variable can be accessed outside the class.
static is a non-access modifier that indicates that a function or variable belongs to the class and not the object.
Example:
public class Foo {
public int a = 9;
public static int b = 10;
}
Foo bar = new Foo();
bar.a; //Works because a is public
Foo.a; //Does not work. a belongs to the object not the class
Foo.b; //Works because b is static
+ 1
Thanks 😊