What is access specifier in java?

In java four visibilities are present to provide to access right of instance variable and methods. The visibilities are as:-

JAVA

  1. Private -> Private visibilities specify that this section can not be access directly from the out side of the object but can be access from any where of object. That means, private section can be access from public, friendly and protected section of the object .So finally we can say that private section is visible in a single object at a time. Private section is not inheritable. That means function and variable present in the private section
  2. Default / Friendly -> the default visibility is friendly in java. The default section can be access directly from the out side of the object. That means the default section can be access in entire program of a particular package (Collection of related class). Default section can be inherited into the subclass. That means variable and function present in the default section. Default section can be override and overwrite in the subclass default section can contains instance variable as well as methods.
  3. Protected -> The protected section can also be access directly from the out side of the object. That means the protected is visible in entire program in a particular package same as default. We know that the default section can not be access in another package but protected section can be access other package in subclass. protected section can not be access in non subclass in other package protected section can contains methods as well as instance variable protected can be inherit into sub class and the method and instance variable can be overwrite and override in the subclass . To protect overwriting and overriding the final keyboard are used before the visibility of function and variable.
  4. Public ->The most visibility in java program is public. The public visibility specifies that this section can be access from any where in java programming. Public section can directly access from out side of object. That means public section is visible in the entire program in a particular package. Public section can also be visible in subclass as well as in non subclass in other package. Public section can be inheriting subclass and can be modified as the requirement of the user.

JAVA

The common name of a set of object is called class. It is also possible to say that class is the blue print or logical design and imaginary design of object. Alternately we can say that class is users define data type. Which is used to create new data type by encapsulating standard data type or other user define data type with there associated member function (methods) in a single unit as the requirement of the user.

This blog written by Jitendra Kumar (Java Trainer at Vtech Academy of Computers)- Java Training Institute in Delhi

0 Responses

  1. December 20, 2016 / 10:05 am

    Your comment is awaiting moderation.

Leave a Reply

Your email address will not be published. Required fields are marked *