+ 4
What is default specifier? (in java) pls explain in simple words...
6 Respuestas
+ 5
public is the default specifier
+ 5
//all members are public by default
class demo {
int x;
}
..
demo d = new demo();
d.x = 23;
System.out.println (d.x);
//explicitly defining
class demo {
private int x;
public void set (int a){
x=a;
}
public void show (){
System.out.println (x);
}
}
..
demo d = new demo();
//compiler error no direct access to private member
//d.x = 23;
d.set(23);
//compiler error no direct access to private member
//System.out.println (d.x);
d.show();
+ 5
Mmmm it's not public, it's actually package private, that is, the class members that have no access modifier (are default) are visible to classes within the same package only.
+ 3
It means that if you skip access specifier while creating class instance data members and instance methods, they are assumed as public
+ 1
aren't they different?? can u pls give me an example to understand(how to use default)!!!
+ 1
its public dont look to much into it if your new becuase you will get million diffrent answers and get confused.