Wednesday 24 July 2013

What is the difference between access specifiers and access modifiers in java?

                   What is the difference between access specifiers and access modifiers in java?


Access specifiers:- By using access specifier we define that who one can access our class/method and variable(or whatever with that we use access specifier ).
Basically java access specifier are four types -

1.public,
2.private,
3.protected, and
4.default


public access specifier :-(Any where)
If you declare any method/function as the public access specifier than that variable/method
can be used anywhere.



private access specifier :-(only till class)
If you declare any method/variable as private than it will only accessed in the same class which declare that method/variable as private.The private members cannot access in the outside world.If any class declared as private than that class will not be inherited.




protected access specifier :-(within a class,within a package and outside package in derived class)
It has same properties as that of private access specifier but it can access the methods/variables in the child class of parent class in which they are declared as protected.When we want to use the private members of parent class in the child class then we declare those variables as protected.



default access specifier :-(Any where in same package)
If you define any method/variable as default or not give any access specifier than the method or variable will be accessed in only that package in which they are defined.They cannot be accessed outside the package.



Access modifiers:- But access modifier are properties of a class/method/variable while access modifier are five types.

1.final
2.static
3.abstract
4.Synchronization and
5.transient











1 comment: