+ 4

What is default specifier? (in java) pls explain in simple words...

11th Jun 2017, 1:34 PM
Harshal Wadhwa
6 odpowiedzi
+ 5
public is the default specifier
11th Jun 2017, 1:45 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 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();
11th Jun 2017, 2:22 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 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.
20th Jul 2017, 1:55 PM
Garikai
Garikai - avatar
+ 3
It means that if you skip access specifier while creating class instance data members and instance methods, they are assumed as public
11th Jun 2017, 2:11 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 1
aren't they different?? can u pls give me an example to understand(how to use default)!!!
11th Jun 2017, 2:01 PM
Harshal Wadhwa
+ 1
its public dont look to much into it if your new becuase you will get million diffrent answers and get confused.
23rd Jul 2017, 11:06 PM
D_Stark
D_Stark - avatar