Powered by Blogger.

Access Modifiers in java



Access Modifiers in java

Java provides a number of access modifiers to set access levels for classes, variables, methods, and constructors. The four access levels are;

  • Visible to the package, the default. No modifiers are needed.
  • Visible to the class only (private).
  • Visible to the world (public).
  • Visible to the package and all subclasses (protected).
Access Modifiers in java


Example of Access Modifiers in java

Variables and methods can be declared without any modifiers, as in the following examples

String version = "1.5.1";
boolean processOrder()
 {
   return true;
}

Default Access Modifier

If you don't use any modifier, it is treated as default bydefault. The default modifier is accessible only within package.

Private Access Modifier

The private access modifier is accessible only within class.

Public Access Modifier

The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.

Protected Access Modifier

The protected access modifier is accessible within package and outside the package but through inheritance only.

Note: Some website called Access Specifier in Java and some website provide tutorial Access Modifier in Java



facebook
google-plus
twitter
pinterest

No comments :

Post a Comment

HTML Tutorial

images

About Sitesbay

This blog is related to Java Tutorial, C++ Tutorial, C Tutorial, Online Earning tips and more in very simple and easy way. Here i will try to give complete idea related to all new technology.

Java Tutorial

Java is Object oriented programming language, It is more secure and high performance language.

C++ Tutorial

C++ is also Object oriented programming language, It is more simple and easy to learn.

 
https://sitesbay.blogspot.com/?utm_medium=d2898efa59afcc0bc411921036e22b767ca37b09