Access Levels are used to define the scope of the members..
There are 4 types of access levels.
There are 4 types of access levels.
- public
- private
- default
- protected
2.private:-it used only in the class.you cannot inherit the private member...
Example
class F cannot inherit the private member of class E.....
3.Default:-it is the default access specifier in java.when you leave the field blank or you didn't mention any access level then it take default access level.it is used inside the whole package but the default member will not inherits in another package.class of another package cannot inherits default member.
Example
class A present in p1 package and class C present in p2 package.we want to use outside the package.Class C cannot inherit class A default member i.
4)protected:-same as default but in this classes of another package inherits the protected member...
Example:-
we can inherit class A protected member of package p1 into class c of package p2 .
Summary:-
public:-everywhere in the .java file
private:-only in the class
protected:-used in the same package and not inherited by class of another package
protected:-used in the same package and inherited by the class of another package..
According to the scope
private<default<protected<public
According to the scope
private<default<protected<public
No comments :
Post a Comment